https://github.com/previousnext/php-prometheus
PHP library for serializing to the Prometheus text format.
https://github.com/previousnext/php-prometheus
Last synced: 10 months ago
JSON representation
PHP library for serializing to the Prometheus text format.
- Host: GitHub
- URL: https://github.com/previousnext/php-prometheus
- Owner: previousnext
- License: gpl-2.0
- Created: 2018-10-03T22:16:40.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-06-04T01:57:49.000Z (almost 2 years ago)
- Last Synced: 2024-12-07T18:36:03.345Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 35.2 KB
- Stars: 6
- Watchers: 8
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# PHP Prometheus Serializer
A PHP library for serializing to the prometheus text format.
[](https://circleci.com/gh/previousnext/php-prometheus)
**NOTE** This library does not keep state. It is intended purely as a serialization library. Therefore, there are no
methods into increment or decrement values for metrics, only to set them in order to be serialized.
## Installation
```
composer require previousnext/php-prometheus
```
## Usage
### Gauge
```php
$gauge = new Gauge("foo", "bar", "A test gauge");
$gauge->set(100, ['baz' => 'wiz']);
$gauge->set(90, ['wobble' => 'wibble', 'bing' => 'bong']);
$gauge->set(0);
$serializer = MetricSerializerFactory::create();
$output = $serializer->serialize($gauge, 'prometheus');
```
Expected output:
```text
# HELP foo_bar A test gauge
# TYPE foo_bar gauge
foo_bar{baz="wiz"} 100
foo_bar{wobble="wibble",bing="bong"} 90
foo_bar 0
```
### Counter
```php
$counter = new Counter("foo", "bar", "A counter for testing");
$counter->set(100, ['baz' => 'wiz']);
$serializer = MetricSerializerFactory::create();
$output = $serializer->serialize($counter, 'prometheus');
```
Expected output:
```text
# HELP foo_bar A counter for testing
# TYPE foo_bar counter
foo_bar{baz="wiz"} 100
```
### Summary
```php
$summary = new Summary("foo", "bar", "Summary help text", 'baz');
$buckets = [0, 0.25, 0.5, 0.75, 1];
$values = [2, 4, 6, 8, 10];
$summary->setValues($buckets, $values);
$summary->setSum(54321);
$summary->setCount(212);
$serializer = MetricSerializerFactory::create();
$output = $serializer->serialize($summary, 'prometheus');
```
Expected output:
```text
# HELP foo_bar Summary help text
# TYPE foo_bar summary
foo_bar{baz="0"} 2
foo_bar{baz="0.25"} 4
foo_bar{baz="0.5"} 6
foo_bar{baz="0.75"} 8
foo_bar{baz="1"} 10
foo_bar_sum 54321
foo_bar_count 212
```
## Developing
PHP CodeSniffer
```
./bin/phpcs
```
PHPUnit
```
./bin/phpunit
```