https://github.com/butschster/prometheus-parser
Prometheus data parser to AST written on PHP8
https://github.com/butschster/prometheus-parser
parser php php8 prometheus
Last synced: 4 months ago
JSON representation
Prometheus data parser to AST written on PHP8
- Host: GitHub
- URL: https://github.com/butschster/prometheus-parser
- Owner: butschster
- License: mit
- Created: 2022-11-02T17:14:43.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-29T07:44:42.000Z (about 3 years ago)
- Last Synced: 2025-10-09T08:32:16.115Z (4 months ago)
- Topics: parser, php, php8, prometheus
- Language: PHP
- Homepage:
- Size: 27.3 KB
- Stars: 10
- Watchers: 1
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Prometheus metrics parser for PHP
[](https://packagist.org/packages/butschster/prometheus-parser)
[](https://packagist.org/packages/butschster/prometheus-parser)
[](https://github.com/butschster/prometheus-parser/actions)
[](https://github.com/butschster/prometheus-parser/actions)
[](https://packagist.org/packages/butschster/prometheus-parser)

Welcome to the Prometheus Metrics Parser! This package makes it easy to extract valuable information from metrics in the Prometheus text-based format. Whether you're looking to analyze your metrics data, integrate it into other systems, or just want a better way to visualize it, this package has you covered.
With just a few lines of code, you can easily extract valuable insights from your Prometheus metrics.
## Requirements
- PHP 8.1 and above
## Quick start
To install the package, run the following command from the root directory of your project:
```shell
composer require butschster/prometheus-parser
```
That's it!
## Usage
To get started, simply pass a string containing your Prometheus metric data to the `parse()` method. The method will return a schema object with metric objects, each of which contains the following properties:
```php
use Butschster\Prometheus\ParserFactory;
$parser = ParserFactory::create();
$schema = $parser->parse(<<getMetrics(); // array of Metric
$metrics['http_requests_total']->description; // The total number of HTTP requests.
$metrics['http_requests_total']->type; // counter
$metrics['http_requests_total']->name; // http_requests_total
foreach ($metrics['go_gc_duration_seconds'] as $metric) {
$metric->name; // go_gc_duration_seconds
$metric->value; // Value
$metric->timestamp; // Timestamp
$metric->lables; // Array of labels
}
```
# Enjoy!
---
## License
The MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information.