【问题标题】:Prometheus Grafana Templating order by countPrometheus Grafana 模板按计数排序
【发布时间】:2017-10-06 18:45:08
【问题描述】:

我正在尝试为每个 API 端点放置一个下拉菜单,以显示 http 请求的 QPS 和延迟(RED 指标)。

我使用了 Grafana 的模板,并使用了以下 prometheus 查询。

label_values(http_duration_milliseconds_count, api_path)

但这里的问题是排序顺序。它显示了一些长尾 api 请求,例如 /admin/phpMyAdmin all。

我只想在此下拉列表中显示按计数排名前 10 位的端点。我如何实现这一目标?

在我的第一个仪表板上附上一张图片以供参考。

【问题讨论】:

    标签: grafana prometheus


    【解决方案1】:

    我们可以使用 query_result 来实现这一点。 http://docs.grafana.org/features/datasources/prometheus/#query-variable

    query_result(topk(10, sort_desc(sum(http_tt_ms_count) by (api_path))))
    

    http_tt_ms_count - 是我的 proemetheus 公制时间序列和所用时间。

    api_path - 是我的标签名称

    这个 query_result 会给出这样的三元组值。

    {api_path="/search/query"} 25704195 1507641522000
    

    使用查询路径中的 Regex 字段仅获取 api 名称。

    *api_path="(.*)".*
    

    这看起来很长,但是

    label_values((topk(10, sort_desc(sum(http_tt_ms_count) by (api_path)))), api_path) 
    

    不在 grafana 中工作,这让我走上了这条路。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-18
      • 2019-12-07
      • 1970-01-01
      • 2020-05-26
      • 1970-01-01
      • 2016-12-01
      相关资源
      最近更新 更多