kafkiansky/push-prometheus

Pushing metrics to prometheus via amphp.

v0.1.1 2022-04-12 15:31 UTC

This package is auto-updated.

Last update: 2024-11-12 20:44:47 UTC


README

test Software License Total Downloads

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.