PHP code example of kibatic / prometheus-metrics-builder

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

    

kibatic / prometheus-metrics-builder example snippets


$metricList = new MetricList();
$metricList->addMetric(new Metric('foo', 1));
$metricList->addMetric(new Metric('bar', "NaN"));
$metricList->addMetric(new Metric(
    'bar',
    1.35,
    [
        'label1' => 'value1',
        'label2' => 'value2',
    ]
));
$response = $metricList->getResponseContent();
$metricList->clearMetrics();

$metric = new Metric(
    'my_metric_name',
    12,
    [
        'module' => 'invoice',
        'instance' => 'value2',
    ],
    new \DateTimeImmutable()
)

$metric = new Metric(
    'foo',
    1,
    [],
    new \DateTimeImmutable('2020-01-01 00:00:00.012')
);