Skip to content

Prometheus

基础概念

  • 数据模型:
  • 时序索引:名字(Metric) 一组 key/value 标签 如http_requests_total{method="POST"}
  • 时序类型(Metric types): Counter Guage(瞬时值) Histogram(一段范围内采样) Summary(同采样)

config

文档地址

scrape_config:

job_name: <job_name>
static_configs:
  [ - <static_config> ... ]

static_configs:

# The targets specified by the static config.
targets:
  [ - '<host>' ]

# Labels assigned to all metrics scraped from the targets.
labels:
  [ <labelname>: <labelvalue> ... ]

测试 config:

promtool check config /etc/prometheus/prometheus.yml

PromQL

http_requests_total{code="200"}
http_requests_total{code!="200"}  // 表示查询 code 不为 "200" 的数据
http_requests_total{code=~"2.."} // 表示查询 code 为 "2xx" 的数据
http_requests_total{code!~"2.."} // 表示查询 code 不为 "2xx" 的数据
floor(avg(http_requests_total{code="200"}))
ceil(avg(http_requests_total{code="200"}))