kafkiansky / push-prometheus
Pushing metrics to prometheus via amphp.
v0.1.1
2022-04-12 15:31 UTC
Requires
- php: ^8.1
- amphp/http-client: ^4.6
Requires (Dev)
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.22
This package is auto-updated.
Last update: 2024-12-12 20:50:13 UTC
README
Contents
Installation
composer require kafkiansky/push-prometheus
Usage
Simple example with default http client:
use Amp\Http\Client\Request; use Kafkiansky\PushPrometheus\Context; use Kafkiansky\PushPrometheus\Metrics\Counter; use Kafkiansky\PushPrometheus\Metrics\Name; use Kafkiansky\PushPrometheus\Metrics\Number; use Kafkiansky\PushPrometheus\Pusher; require_once __DIR__.'/vendor/autoload.php'; Amp\Loop::run(function (): \Generator { $pusher = new Pusher(new Context(host: 'https://pushgateway.test.net/', groups: [ 'job' => 'gateway', 'instance' => 'localhost', ])); yield $pusher->push(new Counter(new Name('test', 'namespace', 'subsystem'), new Number(2))); });
With custom http client:
use Amp\Http\Client\Request; use Kafkiansky\PushPrometheus\Context; use Kafkiansky\PushPrometheus\Metrics\Gauge; use Kafkiansky\PushPrometheus\Metrics\Name; use Kafkiansky\PushPrometheus\Metrics\Number; use Kafkiansky\PushPrometheus\Pusher; use Amp\Http\Client\HttpClient; use Amp\Http\Client\HttpClientBuilder; require_once __DIR__.'/vendor/autoload.php'; Amp\Loop::run(function (): \Generator { $pusher = new Pusher(new Context(host: 'https://pushgateway.test.net/', groups: [ 'job' => 'gateway', 'instance' => 'localhost', ]), function (): HttpClient { return HttpClientBuilder::buildDefault(); }); yield $pusher->push(new Gauge(new Name('test', 'namespace', 'subsystem'), new Number(2))); });
Testing
$ composer test
License
The MIT License (MIT). See License File for more information.