搜索
您的当前位置:首页正文

prometheus 查询长时间段数据时oom问题

来源:哗拓教育

问题描述

单一label的metric浏览长时间数据面板时(比如1周)查询失败并且导致prometheus oom

排障思路

  • 当time series 很长时做数据抽样,比如10W个poinit里抽样1000个点用于绘图
  • 限制内存使用以避免oom

思路落地

数据抽样

搜索grafana文档发下如下配置


image.png
当查询到的样本数据量非常大时可以导致Grafana渲染图标时出现一些性能问题,通过Min Step可以控制Prometheus查询数据时的最小步长(Step),从而减少从Prometheus返回的数据量。
Resolution选项,则可以控制Grafana自身渲染的数据量。例如,如果Resolution的值为1/10,Grafana会将Prometeus返回的10个样本数据合并成一个点。因此Resolution越小可视化的精确性越高,反之,可视化的精度越低。

URL query parameters:

  • query=<string>: Prometheus expression query string.
  • start=<rfc3339 | unix_timestamp>: Start timestamp.
  • end=<rfc3339 | unix_timestamp>: End timestamp.
  • ==step=<duration | float>: Query resolution step width in duration format or float number of seconds.==
  • timeout=<duration>: Evaluation timeout. Optional. Defaults to and is capped by the value of the -query.timeout flag.
  • The data section of the query result has the following format:

限制内存使用以避免oom

从帮助文档里发现--query.max-samples=50000000 即:默认最多加载50000000 samples, 如超过此限制会拒绝query, 因此可根据机器内存合理配置此数值保证不会oom
ps: prometheus version:2.7.1

./prometheus --help
usage: prometheus [<flags>]
      --query.max-samples=50000000 Maximum number of samples a single query can load into memory. Note that queries will fail if they would load more samples than this into memory, so this also limits the number of samples a query can return.

参考文献:./prometheus --help

Top