PHP code example of jlis / php-prometheus

1. Go to this page and download the library: Download jlis/php-prometheus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jlis / php-prometheus example snippets


$adapter = new \Jlis\PhpPrometheus\Adapter\RedisAdapter(['host' => 'localhost']);

$collector = new \Jlis\PhpPrometheus\Collector\MetricsCollector($adapter);

$collector->incrementCount('http_requests_total', 1, ['url' => 'http://foo.bar']);

$collector->updateGauge('current_queue_size', 1337, ['queue' => 'notifications']);

$collector->updateHistogram('some_histogram', 3.5, ['color' => 'blue'], [0.1, 1, 2, 3.5, 4, 5, 6, 7, 8, 9]);

header('Content-Type: ' . \Jlis\PhpPrometheus\Collector\MetricsCollector::MIME_TYPE);

echo $collector->render();
bash
composer