forked from PromPHP/prometheus_client_php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsome_counter.php
29 lines (22 loc) · 836 Bytes
/
some_counter.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
<?php
require __DIR__ . '/../vendor/autoload.php';
use Prometheus\CollectorRegistry;
use Prometheus\Storage\Redis;
$adapter = $_GET['adapter'];
if ($adapter === 'redis') {
Redis::setDefaultOptions(['host' => $_SERVER['REDIS_HOST'] ?? '127.0.0.1']);
$adapter = new Prometheus\Storage\Redis();
} elseif ($adapter === 'apc') {
$adapter = new Prometheus\Storage\APC();
} elseif ($adapter === 'apcng') {
$adapter = new Prometheus\Storage\APCng();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemory();
}
$registry = new CollectorRegistry($adapter);
$count = preg_match('/^[0-9]+$/', $_GET['c'])
? intval($_GET['c'])
: floatval($_GET['c']);
$counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);
$counter->incBy($count, ['blue']);
echo "OK\n";