mirror of
https://github.com/danog/better-prometheus.git
synced 2024-11-26 12:24:39 +01:00
Improve docs
This commit is contained in:
parent
04b1fd085c
commit
99f8d9435a
2
.github/workflows/jekyll-gh-pages.yml
vendored
2
.github/workflows/jekyll-gh-pages.yml
vendored
@ -33,7 +33,7 @@ jobs:
|
|||||||
- name: Build with Jekyll
|
- name: Build with Jekyll
|
||||||
uses: actions/jekyll-build-pages@v1
|
uses: actions/jekyll-build-pages@v1
|
||||||
with:
|
with:
|
||||||
source: ./docs/
|
source: ./
|
||||||
destination: ./_site
|
destination: ./_site
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-pages-artifact@v3
|
uses: actions/upload-pages-artifact@v3
|
||||||
|
@ -46,8 +46,7 @@ $counter->incBy(3, ['type' => 'blue']);
|
|||||||
// ...or add some more default labels to the counter, creating a new counter:
|
// ...or add some more default labels to the counter, creating a new counter:
|
||||||
$newCounter = $counter->addLabels(['someOtherLabel' => 'someOtherDefaultValue']);
|
$newCounter = $counter->addLabels(['someOtherLabel' => 'someOtherDefaultValue']);
|
||||||
assert($newCounter !== $counter); // true
|
assert($newCounter !== $counter); // true
|
||||||
$counter->incBy(3, ['type' => 'blue']);
|
$newCounter->incBy(3, ['type' => 'blue']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Gauges can also be used
|
// Gauges can also be used
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
---
|
|
||||||
description: "A better Prometheus library for PHP applications"
|
|
||||||
title: "danog/better-prometheus"
|
|
||||||
|
|
||||||
---
|
|
||||||
# `danog/better-prometheus`
|
|
||||||
|
|
||||||
A better Prometheus library for PHP applications
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Abstract classes
|
|
||||||
* [\danog\BetterPrometheus\BetterCollector: A better prometheus collector.](danog/BetterPrometheus/BetterCollector.md)
|
|
||||||
|
|
||||||
## Classes
|
|
||||||
* [\danog\BetterPrometheus\BetterCollectorRegistry](danog/BetterPrometheus/BetterCollectorRegistry.md)
|
|
||||||
* [\danog\BetterPrometheus\BetterCounter: A better prometheus counter.](danog/BetterPrometheus/BetterCounter.md)
|
|
||||||
* [\danog\BetterPrometheus\BetterGauge: A better prometheus gauge.](danog/BetterPrometheus/BetterGauge.md)
|
|
||||||
* [\danog\BetterPrometheus\BetterHistogram: A better prometheus histogram.](danog/BetterPrometheus/BetterHistogram.md)
|
|
||||||
* [\danog\BetterPrometheus\BetterSummary: A better prometheus summary.](danog/BetterPrometheus/BetterSummary.md)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
|
||||||
Generated by [danog/phpdoc](https://phpdoc.daniil.it).
|
|
@ -1,90 +1,25 @@
|
|||||||
# better-prometheus
|
---
|
||||||
|
description: "A better Prometheus library for PHP applications"
|
||||||
|
title: "danog/better-prometheus"
|
||||||
|
|
||||||
[![Psalm coverage](https://shepherd.dev/github/danog/better-prometheus/coverage.svg)](https://shepherd.dev/github/danog/better-prometheus)
|
---
|
||||||
[![Psalm level 1](https://shepherd.dev/github/danog/better-prometheus/level.svg)](https://shepherd.dev/github/danog/better-prometheus)
|
# `danog/better-prometheus`
|
||||||
![License](https://img.shields.io/github/license/danog/better-prometheus?v)
|
|
||||||
|
|
||||||
A better Prometheus library for PHP applications.
|
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
|
|
||||||
<?php
|
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
|
||||||
|
|
||||||
use danog\BetterPrometheus\BetterCollectorRegistry;
|
|
||||||
use Prometheus\Storage\InMemory;
|
|
||||||
use Prometheus\Storage\Redis;
|
|
||||||
|
|
||||||
$adapter = new InMemory;
|
|
||||||
// Any other promphp adapter may also be used...
|
|
||||||
// $adapter = new Redis();
|
|
||||||
|
|
||||||
$registry = new BetterCollectorRegistry($adapter);
|
|
||||||
|
|
||||||
// Note the difference with promphp: the labels are keys => 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
|
|
||||||
$counter->incBy(3, ['type' => 'blue']);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Gauges can also be used
|
## Abstract classes
|
||||||
$gauge = $registry->getOrRegisterGauge(
|
* [\danog\BetterPrometheus\BetterCollector: A better prometheus collector.](danog/BetterPrometheus/BetterCollector.md)
|
||||||
'test',
|
|
||||||
'some_gauge',
|
## Classes
|
||||||
'it sets',
|
* [\danog\BetterPrometheus\BetterCollectorRegistry](danog/BetterPrometheus/BetterCollectorRegistry.md)
|
||||||
['someLabel' => 'defaultValue']
|
* [\danog\BetterPrometheus\BetterCounter: A better prometheus counter.](danog/BetterPrometheus/BetterCounter.md)
|
||||||
);
|
* [\danog\BetterPrometheus\BetterGauge: A better prometheus gauge.](danog/BetterPrometheus/BetterGauge.md)
|
||||||
$gauge->set(2.5, ['type' => 'blue']);
|
* [\danog\BetterPrometheus\BetterHistogram: A better prometheus histogram.](danog/BetterPrometheus/BetterHistogram.md)
|
||||||
|
* [\danog\BetterPrometheus\BetterSummary: A better prometheus summary.](danog/BetterPrometheus/BetterSummary.md)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// As well as histograms
|
---
|
||||||
$histogram = $registry->getOrRegisterHistogram(
|
Generated by [danog/phpdoc](https://phpdoc.daniil.it).
|
||||||
'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.
|
|
66
examples/1-all.php
Normal file
66
examples/1-all.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
|
use danog\BetterPrometheus\BetterCollectorRegistry;
|
||||||
|
use Prometheus\Storage\InMemory;
|
||||||
|
use Prometheus\Storage\Redis;
|
||||||
|
|
||||||
|
$adapter = new InMemory;
|
||||||
|
// Any other promphp adapter may also be used...
|
||||||
|
// $adapter = new Redis();
|
||||||
|
|
||||||
|
$registry = new BetterCollectorRegistry($adapter);
|
||||||
|
|
||||||
|
// Note the difference with promphp: the labels are keys => 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']);
|
Loading…
Reference in New Issue
Block a user