简体   繁体   English

带有前缀的所有普罗米修斯指标的 Grafana 变量

[英]Grafana variable for all prometheus metrics with prefix

I would like a Grafana variable that contains all the Prometheus metric names with a given prefix.我想要一个Grafana 变量,其中包含所有具有给定前缀的 Prometheus 指标名称。 I would like to do this so I can control what graphs are displayed with a drop down menu.我想这样做,以便我可以通过下拉菜单控制显示哪些图形。 I'd like to be able to display all the metrics matching the prefix without having to create a query for each one.我希望能够显示与前缀匹配的所有指标,而无需为每个指标创建查询。 In the Grafana documentation under the Prometheus data source I see:在 Prometheus 数据源下的 Grafana 文档中,我看到:

metrics(metric) Returns a list of metrics matching the specified metric regex. metrics(metric) 返回与指定指标正则表达式匹配的指标列表。

-- Using Prometheus in Grafana -- 在 Grafana 中使用 Prometheus

I tried creating a variable in Grafana using this metrics function but it didn't work.我尝试使用这个metrics函数在 Grafana 中创建一个变量,但它没有用。 See the screenshot for the variable settings I have:请参阅我拥有的变量设置的屏幕截图:

settings设置在此处输入图片说明

As you can see the "Preview of values" only shows "None"如您所见,“值预览”仅显示“无”

In promql, you can select metrics by name by using the internal __name__ label:在 promql 中,您可以使用内部__name__标签按名称选择指标:

{__name__=~"mysql_.*"}

And then, you can reuse it to extract the metrics name using query label_values() :然后,您可以重用它来使用查询label_values()提取指标名称:

label_values({__name__=~"mysql_.*"},__name__)

This will populate your variable with metrics name starting with mysql_ .这将使用以mysql_开头的指标名称填充您的变量。

You can get the same result using metrics() ;您可以使用metrics()获得相同的结果; I don't know why it doesn't work for you (it should also works with prefix):我不知道为什么它对你不起作用(它也应该与前缀一起使用):

metrics(mysql_)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM