Exposition formats
As of Prometheus version 2.0, all processes that expose metrics to Prometheus need to use a text-based format. In this section you can find some basic information about this format as well as a more of the format.
Prometheus’ text-based format is line oriented. Lines are separated by a line feed character (\n
). The last line must end with a line feed character. Empty lines are ignored.
Line format
Within a line, tokens can be separated by any number of blanks and/or tabs (and must be separated by at least one if they would otherwise merge with the previous token). Leading and trailing whitespace is ignored.
Comments, help text, and type information
If the token is TYPE
, exactly two more tokens are expected. The first is the metric name, and the second is either counter
, gauge
, histogram
, summary
, or untyped
, defining the type for the metric of that name. Only one TYPE
line may exist for a given metric name. The TYPE
line for a metric name must appear before the first sample is reported for that metric name. If there is no TYPE
line for a metric name, the type is set to untyped
.
The remaining lines describe samples (one per line) using the following syntax (EBNF):
In the sample syntax:
metric_name
andlabel_name
carry the usual Prometheus expression language restrictions.value
is a float represented as required by Go’s function. In addition to standard numerical values,NaN
,+Inf
, and-Inf
are valid values representing not a number, positive infinity, and negative infinity, respectively.- The
timestamp
is anint64
(milliseconds since epoch, i.e. 1970-01-01 00:00:00 UTC, excluding leap seconds), represented as required by Go’sParseInt()
function.
Grouping and sorting
Each line must have a unique combination of a metric name and labels. Otherwise, the ingestion behavior is undefined.
Histograms and summaries
The histogram
and summary
types are difficult to represent in the text format. The following conventions apply:
- The sample sum for a summary or histogram named
x
is given as a separate sample namedx_sum
. - The sample count for a summary or histogram named
x
is given as a separate sample namedx_count
. - Each quantile of a summary named
x
is given as a separate sample line with the same namex
and a label{quantile="y"}
. - Each bucket count of a histogram named
x
is given as a separate sample line with the namex_bucket
and a label{le="y"}
(wherey
is the upper bound of the bucket). - A histogram must have a bucket with
{le="+Inf"}
. Its value must be identical to the value ofx_count
. - The buckets of a histogram and the quantiles of a summary must appear in increasing numerical order of their label values (for the
le
or thequantile
label, respectively).
Below is an example of a full-fledged Prometheus metric exposition, including comments, HELP
and TYPE
expressions, a histogram, a summary, character escaping examples, and more.
# HELP http_requests_total The total number of HTTP requests.
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