本节重点介绍 : prometheus promql简单的总结

  • topk 最值
  • absent nodata报警
  • offset 同环比
  • 分位值histogram_quantile
  • 成功的/总的 = 成功率
  • agg_over_time 横向的聚合

实用功能总结

 查询函数文档

举例

agg 去掉/保留 label ,分布情况
  • 去掉举例:sum without(code) (rate(prometheus_http_requests_total[2m] ) )
  • 保留举例:sum by(code) (rate(prometheus_http_requests_total[2m] ) )
topk bottomK 看top
  • 举例:查看容器cpu使用率top5topk(5,prometheus_http_response_size_bytes_bucket)
  • 最小的 bottomk(5,prometheus_http_response_size_bytes_bucket)
同环比 相减
  • 举例:qps环比1小时 掉10sum (rate(prometheus_http_requests_total[2m] offset 1h) ) - sum (rate(prometheus_http_requests_total[2m] ) )
absent nodata报警
  • ==1代表absent生效
  • 举例:absent(abc_def)==1
分位值histogram_quantile
  • 举例查看apiserver 请求延迟90分位histogram_quantile(0.90, sum(rate(prometheus_http_request_duration_seconds_bucket[5m])) by (le))
两组series关联 成功率百分比
  • 举例:apiserver 请求成功率 100* ( sum(prometheus_http_requests_total{code=~"2.*|3.*"})/ sum(prometheus_http_requests_total) )
agg_over_time 给所有ts的value做agg 横向agg
  • 举例查看一天的alertavg_over_time(go_goroutines [24h])

本节重点总结 : prometheus promql简单的总结

  • topk 最值
  • absent nodata报警
  • 分位值histogram_quantile
  • offset 同环比
  • 成功的/总的 = 成功率
  • agg_over_time 横向的聚合