本文共 1626 字,大约阅读时间需要 5 分钟。
安装 Prometheus 后会暴露一个 /metrics 的 HTTP 服务(相当于安装了 prometheus_exporter),通过配置(默认会加上 /metrics),Prometheus 可以采集到这个 /metrics 里面的所有监控样本数据。例如:
prometheus_http_requests_total{code="200",handler="/api/v1/label/:name/values"} 3 Prometheus 存储的是时序数据,也就是按照时间的维度存储连续的数据集合(指标名称和标签来做唯一标识)。样本格式如下:
prometheus_http_requests_total{code="200",handler="/api/v1/label/:name/values"} @133734964723510 3 其中:
Prometheus 时序格式中包含指标名称和标签。指标名称和标签名/标签值可以包含 ASCII 字母、数字、下划线、冒号,但必须匹配正则表达式 [a-zA-Z_:][a-zA-Z0-9_:]*,即开头的第一个字符不能是数字。
例如:
prometheus_http_requests_total{code="200",handler="/api/v1/label/:name/values"} Counter 是一个单调递增的数值,主要用于记录某段时间内 HTTP 请求的增长率。通过 rate 和 irate 函数可以生成样本数据的变化状况。
Gauge 是一种用于记录可以任意上下变化的数值指标类型,与 Counter 不同,Gauge 适合用来监控瞬时值或频繁变化的值。
Histogram 用于记录数据分布,通过将数据划分成多个桶(buckets),统计每个桶中的样本数量。例如:
prometheus_http_request_duration_seconds_bucket{handler="/metrics",le="0.1"} 612 Summary 用于观察和聚合时间持续性或大小的指标类型,与 Histogram 类似,但更关注分位数。Summary 会自动计算请求延迟、响应时间等的分位数,同时还会维护时间的总数和。
所有可以向 Prometheus 提供监控样本数据的程序都可以被称为一个 Exporter。Prometheus 通过轮询的方式,定期从这些目标(Target)中获取样本数据。
所有 Exporter 程序都需要按照 Prometheus 的规范返回监控样本数据。例如,Node Exporter 访问 http://env-base:9100/metrics 会返回如下内容:
# HELP prometheus_tsdb_wal_fsync_duration_seconds_count 1# TYPE: countprometheus_tsdb_wal_fsync_duration_seconds_count 2
样本数据规范:
转载地址:http://ahxfk.baihongyu.com/