https://github.com/danog/better-prometheus
A better Prometheus library for PHP applications.
https://github.com/danog/better-prometheus
prometheus prometheus-exporter prometheus-metrics
Last synced: 5 months ago
JSON representation
A better Prometheus library for PHP applications.
- Host: GitHub
- URL: https://github.com/danog/better-prometheus
- Owner: danog
- License: apache-2.0
- Created: 2024-05-03T14:55:59.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-09T19:11:46.000Z (about 2 years ago)
- Last Synced: 2025-12-09T13:17:50.694Z (7 months ago)
- Topics: prometheus, prometheus-exporter, prometheus-metrics
- Language: PHP
- Homepage:
- Size: 26.4 KB
- Stars: 13
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# better-prometheus
[](https://shepherd.dev/github/danog/better-prometheus)
[](https://shepherd.dev/github/danog/better-prometheus)

A better Prometheus library for PHP applications.
Offers a modern, clean PHP 8.1 API, with support for **default label values**, based on and compatible with the original `promphp/prometheus_client_php` library.
## Installation
```bash
composer require danog/better-prometheus
```
## Usage
```php
values, not just keys.
$counter = $registry->getOrRegisterCounter(
'test',
'some_counter',
'it increases',
// Note: these are default label key+values, they will be sent verbatim, no changes
['someLabel' => 'defaultValue']
);
// Specify some additional labels post-construction like this (both keys and values)...
$counter->incBy(3, ['type' => 'blue']);
// ...or add some more default labels to the counter, creating a new counter:
$newCounter = $counter->addLabels(['someOtherLabel' => 'someOtherDefaultValue']);
assert($newCounter !== $counter); // true
$newCounter->incBy(3, ['type' => 'blue']);
// Gauges can also be used
$gauge = $registry->getOrRegisterGauge(
'test',
'some_gauge',
'it sets',
['someLabel' => 'defaultValue']
);
$gauge->set(2.5, ['type' => 'blue']);
// As well as histograms
$histogram = $registry->getOrRegisterHistogram(
'test',
'some_histogram',
'it observes',
['someLabel' => 'defaultValue'],
// [0.1, 1, 2, 3.5, 4, 5, 6, 7, 8, 9]
);
$histogram->observe(3.5, ['type' => 'blue']);
// And suummaries
$summary = $registry->getOrRegisterSummary(
'test',
'some_summary',
'it observes a sliding window',
['someLabel' => 'defaultValue'],
// 84600,
// [0.01, 0.05, 0.5, 0.95, 0.99]
);
$summary->observe(5, ['type' => 'blue']);
```
## API documentation
See [here »](https://daniil.it/better-prometheus/docs/) for the full API documentation.