Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 3 months ago
JSON representation

Prometheus data parser to AST written on PHP8

Awesome Lists containing this project

README

        

# Prometheus metrics parser for PHP

[![PHP Version Require](https://poser.pugx.org/butschster/prometheus-parser/require/php)](https://packagist.org/packages/butschster/prometheus-parser)
[![Latest Stable Version](https://poser.pugx.org/butschster/prometheus-parser/v/stable)](https://packagist.org/packages/butschster/prometheus-parser)
[![phpunit](https://github.com/butschster/prometheus-parser/actions/workflows/phpunit.yml/badge.svg)](https://github.com/butschster/prometheus-parser/actions)
[![psalm](https://github.com/butschster/prometheus-parser/actions/workflows/psalm.yml/badge.svg)](https://github.com/butschster/prometheus-parser/actions)
[![Total Downloads](https://poser.pugx.org/butschster/prometheus-parser/downloads)](https://packagist.org/packages/butschster/prometheus-parser)

![Github cover Prometheus parser](https://user-images.githubusercontent.com/773481/199663705-3540ce54-086e-476e-bf91-cd607c98df9f.jpg)

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.