Grafana模板:Prometheus label_values变量的正则表达式

时间:2019-07-30 07:51:56

标签: grafana prometheus grafana-templating

我正在尝试使用 label_values 函数在Grafana中设置模板。 该文档指定了查询label_values的可能性,例如:

label_values(metric, label)

在我的用例中,有两个主要的指标组,其名称类似于:

  • app1_current_sensor1
  • app1_current_sensor2
  • app2_current_sensor2
  • app2_current_sensor3

每个标签都有一个名为“ uid”的标签。 我希望使用上面的查询来仅过滤一个仪表板上的'app1'和另一个仪表板上的'app2'的用户ID。

我尝试过

label_values(app1_current_sensor1, uid)

但是,如果由于某种原因sensor1在一段时间内未发送数据,即使sensor2正在发送数据,我也不会在仪表板上看到用户ID。

是否可以使用正则表达式作为度量标准变量的输入? 这样的事情对我有用:

label_values(metric=~(app1_[^\s]+), uid)

但是我不确定在Grafana中是否可行。

1 个答案:

答案 0 :(得分:1)

以下表达式选择名称以job_开头且标签为method="GET"的所有度量标准

{__name__=~"job_.*", method="GET"}

要获取所有名称以app1_开头的指标,请使用

{__name__=~"app1_.*"}

要获取名称以app1_uid开头的所有度量等于某个特定值的所有度量,请使用

 {__name__=~"app1_.*", uid="value"}