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

Pie*_*ens 1 grafana prometheus grafana-templating

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

label_values(metric, label)
Run Code Online (Sandbox Code Playgroud)

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

  • app1_current_sensor1
  • app1_current_sensor2
  • app2_current_sensor2
  • app2_current_sensor3

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

我试过了

label_values(app1_current_sensor1, uid)
Run Code Online (Sandbox Code Playgroud)

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

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

label_values(metric=~(app1_[^\s]+), uid)
Run Code Online (Sandbox Code Playgroud)

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

Kam*_*san 8

以下表达式选择名称以 开头job_并带有标签的所有指标method="GET"

{__name__=~"job_.*", method="GET"}
Run Code Online (Sandbox Code Playgroud)

获取名称以app1_use开头的所有指标

{__name__=~"app1_.*"}
Run Code Online (Sandbox Code Playgroud)

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

 {__name__=~"app1_.*", uid="value"}
Run Code Online (Sandbox Code Playgroud)

  • 惊人的!**__name__** 正是我正在寻找的:) 谢谢您将其与 label_values 一起使用,如下所示: `label_values({__name__=~"app1_.*"}, uid)` (2认同)