资讯动态

Prometheus 如何开启 exemplar-storage 特性存储抓取到的 Exemplars

发布时间:2026/9/13 8:00:59 来源:尧图企业网站定制
Prometheus 如何开启 exemplar-storage 特性存储抓取到的 Exemplars【免费下载链接】prometheusThe Prometheus monitoring system and time series database.项目地址: https://gitcode.com/GitHub_Trending/pr/prometheusPrometheus 默认不存储 Exemplars示例样本通常携带trace_id之类的标签用于把指标采样关联到具体的程序跟踪。如果你希望 Prometheus 把抓取目标在 OpenMetrics 中上报的 Exemplars 保存下来并支持查询需要显式开启实验特性exemplar-storage。本文基于当前仓库文档给出从开启特性、配置缓冲区大小到通过 HTTP API 验证结果的完整操作路径。开启 exemplar-storage 特性Exemplars storage 是实验特性默认关闭。根据 docs/feature_flags.md通过--enable-feature命令行标志开启支持逗号分隔同时启用多个特性prometheus --enable-featureexemplar-storage开启后 Prometheus 会存储从抓取目标中抓取到的 Exemplars。文档说明了该特性的存储实现和内存开销Exemplar 存储实现为一个固定大小的环形缓冲区circular buffer在内存中为所有序列series保存 Exemplars一条仅带trace_idjaeger-trace-id标签的 Exemplar通过内存 exemplar 存储大约占用100 字节该特性被启用后Exemplars 同时会追加写入 WAL 做本地持久化持久化时长取决于 WAL 的保留配置。特性列表可通过--enable-feature的合法取值确认exemplar-storage在 docs/command-line/prometheus.md 的合法选项清单中列出。配置 Exemplars 缓冲区大小特性开启后可以通过配置文件中storage段下的exemplars子段控制环形缓冲区大小。根据 docs/configuration/configuration.md配置结构如下storage段内的相关字段# Storage related settings that are runtime reloadable. storage: [ tsdb: tsdb ] [ exemplars: exemplars ]exemplars段只有一个字段# Configures the maximum size of the circular buffer used to store exemplars for all series. Resizable during runtime. [ max_exemplars: int | default 100000 ]即max_exemplars配置所有序列共享的 Exemplar 环形缓冲区的最大大小默认值为100000且支持运行时调整runtime resizable。结合上面的字段一个启用特性并显式设置缓冲区上限的完整配置示例为storage: exemplars: max_exemplars: 100000文档同时强调exemplar storage is still considered experimental and must be enabled via --enable-featureexemplar-storage即配置文件中的exemplars段只有在特性开启后才起作用。验证 Exemplars 是否被存储开启特性后可以用 HTTP API 查询指定时间范围内的 Exemplars。根据 docs/querying/api.mdquery_exemplars端点标注为 experimental返回对某个合法 PromQL 查询在给定时间范围内的 Exemplar 列表GET /api/v1/query_exemplars POST /api/v1/query_exemplars支持的 URL 查询参数querystringPrometheus 表达式查询字符串startrfc3339 | unix_timestamp起始时间戳endrfc3339 | unix_timestamp结束时间戳。文档给出的调用示例注意query是 PromQL 表达式需要替换为你实际带有 Exemplars 的指标名start/end替换为你需要的时间范围curl -g http://localhost:9090/api/v1/query_exemplars?querytest_exemplar_metric_totalstart2020-09-14T15:22:25.479Zend2020-09-14T15:23:25.479Z文档示例的返回结构示例结果字段值不要作为固定预期{ status: success, data: [ { seriesLabels: { __name__: test_exemplar_metric_total, instance: localhost:8090, job: prometheus, service: bar }, exemplars: [ { labels: { trace_id: EpTxMJ40fUus7aGY }, value: 6, timestamp: 1600096945.479 } ] } ] }当data中对应seriesLabels的exemplars数组包含条目含labels、value、timestamp时说明该序列在该时间窗口内存储了 Exemplars特性已生效。特性状态确认与限制query_exemplarsAPI 与 exemplar 存储本身一样都被标注为实验特性experimental文档提示行为可能在未来版本变化如果后续还需要把 Exemplars 经 remote write 转发对应配置为 remote write 段中的send_exemplars: boolean默认false文档明确说明exemplar storage itself must be enabled for exemplars to be scraped in the first place——即必须先开启exemplar-storage特性send_exemplars才有意义。Exemplars 的内存占用随抓取目标上报的 Exemplar 数量增长文档给出的参考值是单条约 100 字节可通过max_exemplars限制缓冲区规模超出缓冲区容量的旧 Exemplar 会被环形缓冲淘汰这是该实现方式的固有行为文档未提供其他保留策略。相关文档特性说明与开启方式docs/feature_flags.md配置项storage.exemplars/max_exemplarsdocs/configuration/configuration.mdquery_exemplars查询端点docs/querying/api.md--enable-feature合法取值列表docs/command-line/prometheus.md【免费下载链接】prometheusThe Prometheus monitoring system and time series database.项目地址: https://gitcode.com/GitHub_Trending/pr/prometheus创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价