promphp/prometheus_push_gateway_php

PHP应用程序的Prometheus Push Gateway客户端。

v1.1.1 2022-04-11 18:49 UTC

This package is auto-updated.

Last update: 2024-09-12 00:44:38 UTC


README

Tests

本包提供了一个简单的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']);

也请参阅示例

开发

依赖项

黑盒测试

只需使用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/