alan/msf-prometheus

msf support prometheus

v1.0.5 2023-04-20 06:47 UTC

This package is auto-updated.

Last update: 2024-10-21 07:22:11 UTC


README

接入步骤:

  1. 定义prometheus使用的redis配置
$config['redis']['prometheus']['ip']               = '127.0.0.1';
$config['redis']['prometheus']['port']             = 6379;
$config['redis']['prometheus']['select']           = 0;
$config['redis']['prometheus']['password']         = '123456';
  1. 引入prometheus组件,在入口文件(server.php)添加如下代码

    \alan\msf_prometheus\di\ClassLoader::init();
  2. 添加支持/metrics路由,创建控制器 app/Controllers/Metrics.php

    <?php
    
    namespace App\Controllers;
    
    use alan\msf_prometheus\prometheus\MetricsTrait;
    use PG\MSF\Controllers\Controller;
    
    class Metrics extends Controller
    {
        use MetricsTrait;
    
        public function actionIndex(){
            $result = yield $this->metricsOutput();
            $this->getContext()->getOutput()->setContentType("text/plain; version=0.0.4;charset=UTF-8");
            $this->getContext()->getOutput()->end($result);
        }
    }
  3. 指标示例

    # HELP http_server_requests_code_total http server requests count.
    # TYPE http_server_requests_code_total counter
    http_server_requests_code_total{path="/metrics",code="",method="GET"} 16170
    # TYPE http_server_requests_duration_ms histogram
    http_server_requests_duration_ms_bucket{path="/metrics",le="25"} 16124
    http_server_requests_duration_ms_bucket{path="/metrics",le="50"} 16162
    http_server_requests_duration_ms_bucket{path="/metrics",le="100"} 16168
    http_server_requests_duration_ms_bucket{path="/metrics",le="250"} 16170
    http_server_requests_duration_ms_bucket{path="/metrics",le="500"} 16170
    http_server_requests_duration_ms_bucket{path="/metrics",le="1000"} 16170
    http_server_requests_duration_ms_bucket{path="/metrics",le="1500"} 16170
    http_server_requests_duration_ms_bucket{path="/metrics",le="2000"} 16170
    http_server_requests_duration_ms_bucket{path="/metrics",le="3000"} 16170
    http_server_requests_duration_ms_bucket{path="/metrics",le="+Inf"} 16170
    http_server_requests_duration_ms_count{path="/metrics"} 16170
    http_server_requests_duration_ms_sum{path="/metrics"} 49693
  4. 尽情使用...