The Prometheus Text FormatBlog

What is the Prometheus text format and where is it used?


BY Julien Pivotto / ON Nov 15, 2023

Overview of the Prometheus Text Format

In order to retrieve your metrics in Prometheus, they need to be exposed to the server. Let’s look into the Prometheus Text Format, the most commonly used format for presenting metrics to the server.

The Prometheus Text Format is a widely adopted format to expose metrics, and it is, next to the OpenMetrics text format and the Prometheus Protobuf format, adopted by Prometheus.

It must be exposed over HTTP to be scraped. However, it is also utilized in other contexts, such as the Node Exporter Textfile Collector and the Pushgateway API.

The format consists of a series of lines, each representing a metric. A metric consists of a name/value pair with an optional timestamp. The minimal format of metrics is:

<metric name with labels> <value> [<timestamp>]

The timestamp is optional. In the Prometheus Text Format, it is a Unix Timestamp expressed in milliseconds.

In practice, here is a Prometheus metric:

promhttp_metric_handler_requests_total{code="200"} 419

Labels are optional. Upon ingestion, the Prometheus server adds more labels, often job and instance.

Metadata can be added, in the form of # HELP and # TYPE lines:

# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP
status code.
# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 419
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0

This metadata is helpful in providing context about metrics and the functions to apply to them.

If you are having trouble expressing your metrics, you can get in touch with us.


to our newsletter