2017-10-06 500 views
1

我试图为每个API端点放置一个下拉菜单,它将显示http请求(RED度量)的QPS和延迟。Prometheus Grafana模板按次序排列

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

label_values(http_duration_milliseconds_count, api_path) 

但这里的问题是排序顺序。它显示了一些像/ admin/phpMyAdmin这样的longtail api请求。

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

在我的第一个仪表板上附加了一张图像供参考。

enter image description here

回答

2

我们可以使用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 

使用正则表达式在查询路径只拿到了API名称。

*api_path="(.*)".* 

这看起来像一个很长的路要走,但

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

不在这让我进入这条道路grafana工作。