-
Notifications
You must be signed in to change notification settings - Fork 1
/
pushgateway.php
39 lines (31 loc) · 1.3 KB
/
pushgateway.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
use Enalean\Prometheus\PushGateway\PSR18Pusher;
use Enalean\Prometheus\Registry\CollectorRegistry;
use Enalean\Prometheus\Storage\RedisStore;
use Enalean\Prometheus\Value\MetricLabelNames;
use Enalean\Prometheus\Value\MetricName;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
$adapter = $_GET['adapter'] ?? '';
if ($adapter === 'redis') {
$redisClient = new Redis();
$redisClient->connect($_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$adapter = new RedisStore($redisClient);
} elseif ($adapter === 'apcu') {
$adapter = new Enalean\Prometheus\Storage\APCUStore();
} elseif ($adapter === 'in-memory') {
$adapter = new Enalean\Prometheus\Storage\InMemoryStore();
} else {
$adapter = new Enalean\Prometheus\Storage\NullStore();
}
$registry = new CollectorRegistry($adapter);
$counter = $registry->registerCounter(
MetricName::fromNamespacedName('test', 'some_counter'),
'it increases',
MetricLabelNames::fromNames('type'),
);
$counter->incBy(6, 'blue');
$pusher = new PSR18Pusher('192.168.59.100:9091', Psr18ClientDiscovery::find(), Psr17FactoryDiscovery::findRequestFactory(), Psr17FactoryDiscovery::findStreamFactory());
$pusher->push($registry, 'my_job', ['instance' => 'foo']);