promphp / prometheus_push_gateway_php
PHP应用程序的Prometheus Push Gateway客户端。
v1.1.1
2022-04-11 18:49 UTC
Requires
- php: ^7.2|^8.0
- guzzlehttp/guzzle: ^6.3|^7.0
- promphp/prometheus_client_php: ^1.0|^2.0
Requires (Dev)
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^0.12.50
- phpstan/phpstan-phpunit: ^0.12.16
- phpstan/phpstan-strict-rules: ^0.12.5
- phpunit/phpunit: ^8.4|^9.4
- squizlabs/php_codesniffer: ^3.5
README
本包提供了一个简单的PHP API来访问Prometheus Push Gateway。它曾是promphp/prometheus_client_php的一部分,并在Prometheus Client PHP版本2.0.0时被独立为一个包。
它是如何工作的?
PushGateway允许Prometheus从不可访问的系统(您的Prometheus无法访问的系统)获取指标。通过这个库,您可以轻松地将您的指标发送到PushGateway。
安装
添加为Composer依赖项
composer require promphp/prometheus_push_gateway_php
用法
假设您有一个简单的计数器,并想将其发送到您的PushGateway。
\Prometheus\CollectorRegistry::getDefault() ->getOrRegisterCounter('', 'some_quick_counter', 'just a quick measurement') ->inc(); // Now send it to the PushGateway: $pushGateway = new \PrometheusPushGateway\PushGateway('http://192.168.59.100:9091'); $pushGateway->push(\Prometheus\CollectorRegistry::getDefault(), 'my_job', ['instance' => 'foo']);
也请参阅示例。
开发
依赖项
- PHP ^7.2 | ^8.0
- Composer
黑盒测试
只需使用docker-compose启动PushGateway
docker-compose up
使用Composer获取所有依赖项
docker run --rm --interactive --tty --volume $PWD:/app composer install
执行测试
docker-compose run phpunit vendor/bin/phpunit tests/Test/