Exposition formats

基于文本的格式

基本信息

方面 描述
起始时间 2014 年 4 月
支持版本 Prometheus 版本 >=0.4.0
传输 HTTP
编码 UTF-8, \n 换行符
HTTP Content-Type
可选 HTTP Content-Encoding gzip
优点
  • 人类可读
  • 易于组装,尤其对于极简情况(无需嵌套)
  • 逐行可读(类型提示和文档字符串除外)
局限性
  • 冗长
  • 解析成本
支持的指标原语
  • Counter
  • Gauge
  • Histogram
  • Summary
  • Untyped

文本格式详情

行格式

注释、帮助文本和类型信息

metric_name [
  "{" label_name "=" `"` label_value `"` { "," label_name "=" `"` label_value `"` } [ "," ] "}"
] value [ timestamp ]

在样本语法中

分组和排序

直方图和摘要

文本格式示例

# 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

OpenMetrics 文本格式

Exemplars (Experimental)

Protobuf 格式

以下是实验性功能列表,一旦启用,将配置 Prometheus 以优先使用 Protobuf exposition format

功能标志 引入它的版本
native-histograms 2.40.0
created-timestamp-zero-ingestion 2.50.0

历史版本