【问题标题】:How can I filter the result of label_values(label) to get a list of labels that match a regex?如何过滤 label_values(label) 的结果以获取与正则表达式匹配的标签列表?
【发布时间】:2019-09-21 08:10:51
【问题描述】:

我有几个带有“服务”标签的指标。我想获取以“abc”开头并以“xyz”结尾的所有“服务”级别的列表。这些将是 grafana 模板变量的值。

这是我尝试过的: label_values(service) =~ "abc.*xyz"

但是这会产生错误Template variables could not be initialized: parse error at char 13: could not parse remaining input "(service_name) "...

关于如何过滤标签值的任何想法?

【问题讨论】:

    标签: grafana prometheus promql


    【解决方案1】:

    这应该有效(用您提到的指标替换 up):

    label_values(up{service=~"abc.*xyz"}, service)
    

    或者,如果您确实需要查看多个指标(假设出于某种原因,某些指标具有某些服务标签值,而其他指标具有其他值):

    label_values({__name__=~"metric1|metric2|metric3", service=~"abc.*xyz"}, service)
    

    【讨论】:

    • 如果您想要的过滤器是一个 grafana 图形变量怎么办 - 其中 abc.* 是 grafana 下拉列表中的过滤器。 PromQL 中的变量可以用作 $grafana_Var 还是 ${{grafana_Var}}....
    • 根据 Grafana 文档 (grafana.com/docs/reference/templating),$grafana_Var[[grafana_Var]] 都应该可以工作。虽然(在不相关的注释上)这个名字看起来很不寻常。我见过snake_case 名称和camelCase 名称,但从未见过snake_Camel_Case 名称。 (o:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 2011-04-12
    • 2016-07-18
    • 2016-11-10
    相关资源
    最近更新 更多