PHP code example of krenor / prometheus-client

1. Go to this page and download the library: Download krenor/prometheus-client 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/ */

    

krenor / prometheus-client example snippets




use Krenor\Prometheus\Metrics\Metric;
use Krenor\Prometheus\Metrics\Counter;
use Krenor\Prometheus\CollectorRegistry;
use Krenor\Prometheus\Renderer\TextRenderer;
use Krenor\Prometheus\Storage\StorageManager;
use Krenor\Prometheus\Storage\Repositories\InMemoryRepository;
use Krenor\Prometheus\Tests\Stubs\MultipleLabelsCounterStub as ExampleCounter;

Metric::storeUsing(new StorageManager(new InMemoryRepository));

$registry = new CollectorRegistry;

$counter = $registry->register(new ExampleCounter);

$counter->increment(['some', 'label', 'values']);
$counter->incrementBy(3, ['foo', 'bar', 'baz']);

$samples = $registry->collect();
$metrics = (new TextRenderer)->render($samples);