aleteus / prometheus_client_php
PHP应用程序的Prometheus仪表库。
1.0.1
2019-10-04 10:46 UTC
Requires
- php: ^7.1
- ext-json: *
- guzzlehttp/guzzle: ^6.2
- symfony/polyfill-apcu: ^1.6
Requires (Dev)
- phpunit/phpunit: ^7.5
Suggests
- ext-apc: Required if using APCu.
- ext-redis: Required if using Redis.
README
安装
composer require aleteus/prometheus_client_php
如何使用?
$parameters = [ 'name1' => $var1, 'name2' => $var2, 'name3' => $var3 ]; $prometheus = new PrometheusClient( '*:9091', 'nome', 'da_metrica', 'produto', $parameters, 'tipo da metrica (histogram, counter ou gauge)', 'nome_da_aplicação'); $prometheus->pushGateway($timeProcess, $parameters, $help);
解释
参数
- 参数存储额外的信息,这些信息根据监控需求选择,并以'标签'的形式显示在Pushgateway界面上,这些标签将在Grafana构建图表时被处理。这保持了'名称1' => $var1的格式。'名称1'用于指示变量'$var1'的值。
Prometheus
- 客户端由七个参数创建
- Pushgateway地址
- 指标名称(由两个字符串分隔)
- 产品名称
- 自己的$parameters
- 指标类型
- 应用程序名称
示例
$prometheus = new PrometheusClient( '*:9091', 'nome', 'da_metrica', 'produto', $parameters, 'tipo da metrica (histogram, counter ou gauge)', 'nome_da_aplicação'); $prometheus->pushGateway($timeProcess, $parameters, $help);
Pushgateway
$prometheus->pushGateway($timeProcess, $parameters, $help);
这部分代码负责将所有信息发送到Prometheus和Pushgateway,它有三个必填参数:($timeProcess, $parameters, $help)。
$timeprocess
需要具有代码处理过程中的某个时刻的值。$parameters
将发送我们在前面的示例中创建的数组。- 而
$help
将包含您希望存储在Pushgateway中的额外信息。
- 注意:如果这些参数中的任何一个为空,则发送将不会工作!
指标类型
直方图
- 直方图捕获事件及其发生频率。
计数器
- 计数器具有其自身含义,简单地是一个计数器,在进程结束时重置。
仪表
仪表与计数器类似,但仪表的值可以上升或下降。