jlis / php-prometheus
A PHP client for Prometheus.
v1.0.1
2018-09-11 09:20 UTC
Requires
- php: >=5.6.3
- jimdo/prometheus_client_php: dev-apcu
Requires (Dev)
- phpunit/phpunit: 5.7
- squizlabs/php_codesniffer: ^3.0@dev
This package is auto-updated.
Last update: 2024-12-12 04:41:48 UTC
README
A PHP client for Prometheus
Install
Require this package with composer using the following command:
composer require jlis/php-prometheus
Usage
First create an adapter:
$adapter = new \Jlis\PhpPrometheus\Adapter\RedisAdapter(['host' => 'localhost']);
Next, you may pass it to the collector and start collecting metrics:
$collector = new \Jlis\PhpPrometheus\Collector\MetricsCollector($adapter);
Counts
$collector->incrementCount('http_requests_total', 1, ['url' => 'http://foo.bar']);
Gauge
$collector->updateGauge('current_queue_size', 1337, ['queue' => 'notifications']);
Histogram
$collector->updateHistogram('some_histogram', 3.5, ['color' => 'blue'], [0.1, 1, 2, 3.5, 4, 5, 6, 7, 8, 9]);
Expose the metrics
header('Content-Type: ' . \Jlis\PhpPrometheus\Collector\MetricsCollector::MIME_TYPE); echo $collector->render();
Note: Be sure to set the correct content type for Prometheus.
Adapters
The following adapters are available:
\Jlis\PhpPrometheus\Adapter\InMemoryAdapter
uses a plain PHP array, only suitable for testing.\Jlis\PhpPrometheus\Adapter\RedisAdapter
uses Redis and requires theext-redis
PHP extension.\Jlis\PhpPrometheus\Adapter\ApcuAdapter
uses APCu and requires theext-apcu
PHP extension.
You can easily create your own storage adapter by extending the \Jlis\PhpPrometheus\Adapter\AbstractAdapter
class.