openmetrics-php / exposition-text Goto Github PK
View Code? Open in Web Editor NEWImplementation of the text exposition format of OpenMetrics
License: MIT License
Implementation of the text exposition format of OpenMetrics
License: MIT License
The library also installs/works on PHP 7.1.
The library only installs/works on PHP >= 7.2
Back porting to PHP 7.1 was originally requested via Twitter
/cc @s7anley
The output of a counter metric for metric name a
must be a_total
by this convention.
The output of a counter metric for metric name a
is a
.
Counters add automatically _total
suffix to metric itself, but it does not work for TYPE and HELP, so in fact you get descrepancy between metric definition and actual name. I think this commit must be reverted, people should be able to manage metric names without any magic in code: 78bc5df
# TYPE your_metric_name_total counter
# HELP your_metric_name_total A helpful description of your measurement.
your_metric_name_total 1.000000
As described in README (and really works this way):
# TYPE your_metric_name counter
# HELP your_metric_name A helpful description of your measurement.
your_metric_name_total 1.000000
Any of examples here: https://github.com/openmetrics-php/exposition-text/blob/master/examples/counters.php
All produces metrics must be able to be parsed by the openmetrics python parser.
Metrics are only tested via unit tests.
The following script is able to parse a file that contains exposed metrics.
Install prometheus_client
and forked-path
:
pip install prometheus_client forked-path
parseFile.py:
from prometheus_client.openmetrics.parser import text_string_to_metric_families
from path import path
metrics = path('/path/to/metrics.txt').bytes()
for family in text_string_to_metric_families(metrics):
for sample in family.samples:
print("Name: {0} Labels: {1} Value: {2} Timestamp: {3}".format(*sample))
I don't think this package should rely on psr/http-message.
It should be the client responsibility to expose the metrics.
At most some recommendations/examples can be provided.
Most likely many of the clients already use a framework that uses the psr7, meaning they should just hook it up themselves - also this can bring in conflicts for frameworks using psr/http-message: ^2.0 dependency.
Or as in my case, I have to bring in an unwanted dependency because I just want to dump the metrics directly to a file.
What do you think?
Should work on PHP 8.1+ :-)
Deprecated: Return type of OpenMetricsPhp\Exposition\Text\Collections\LabelCollection::getIterator(): iterable should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/openmetrics-php/exposition-text/src/Collections/LabelCollection.php on line 65
There are probably some more.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.