butschster/prometheus-parser

Prometheus parser written on PHP 8

Maintainers

👁 butschster

Package info

github.com/butschster/prometheus-parser

pkg:composer/butschster/prometheus-parser

Statistics

Installs: 800

Dependents: 0

Suggesters: 0

Stars: 10

Open Issues: 1

1.3.2 2026-04-20 18:54 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 60a1fc5e1ca9c70e1a9f73c9cf092a24e06a7987

  • Pavel Buchnev <butschster.woop@gmail.com>

phpddlprometheusphp8prometheus-parser

This package is auto-updated.

Last update: 2026-06-11 05:50:43 UTC


README

👁 PHP Version Require
👁 Latest Stable Version
👁 phpunit
👁 psalm
👁 Total Downloads

👁 Github cover 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:

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:

use Butschster\Prometheus\ParserFactory;

$parser = ParserFactory::create();

$schema = $parser->parse(<<<'SCHEMA'
# HELP http_requests_total The total number of HTTP requests.
# TYPE http_requests_total counter
http_requests_total{method="post",code="200"} 1027 1395066363000
http_requests_total{method="post",code="400"} 3 1395066363000

# Escaping in label values:
msdos_file_access_time_seconds{path="C:\\DIR\\FILE.TXT",error="Cannot find file:\n\"FILE.TXT\""} 1.458255915e9

# Minimalistic line:
metric_without_timestamp_and_labels 12.47

# A weird metric from before the epoch:
something_weird{problem="division by zero"} +Inf -3982045

# A histogram, which has a pretty complex representation in the text format:
# HELP http_request_duration_seconds A histogram of the request duration.
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{le="0.05"} 24054
http_request_duration_seconds_bucket{le="0.1"} 33444
http_request_duration_seconds_bucket{le="0.2"} 100392
http_request_duration_seconds_bucket{le="0.5"} 129389
http_request_duration_seconds_bucket{le="1"} 133988
http_request_duration_seconds_bucket{le="+Inf"} 144320
http_request_duration_seconds_sum 53423
http_request_duration_seconds_count 144320

# Finally a summary, which has a complex representation, too:
# HELP rpc_duration_seconds A summary of the RPC duration in seconds.
# TYPE rpc_duration_seconds summary
rpc_duration_seconds{quantile="0.01"} 3102
rpc_duration_seconds{quantile="0.05"} 3272
rpc_duration_seconds{quantile="0.5"} 4773
rpc_duration_seconds{quantile="0.9"} 9001
rpc_duration_seconds{quantile="0.99"} 76656
rpc_duration_seconds_sum 1.7560473e+07
rpc_duration_seconds_count 2693
 SCHEMA
);

Schema data

$metrics = $schema->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->labels; // Array of labels
}

Enjoy!

License

The MIT License (MIT). Please see LICENSE for more information.