alan / msf-prometheus
msf support prometheus
v1.0.5
2023-04-20 06:47 UTC
Requires
- php: ^7.1.3
- nikic/php-parser: ^4.13
- roave/better-reflection: ^3.3
- symfony/finder: ^4.1.0
README
接入步骤:
- 定义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';
-
引入prometheus组件,在入口文件(server.php)添加如下代码
\alan\msf_prometheus\di\ClassLoader::init();
-
添加支持/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); } }
-
指标示例
# 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
-
尽情使用...