将字符串追加到grafana查询中的变量? [英] append string to variable in a grafana query?

查看:835
本文介绍了将字符串追加到grafana查询中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Grafana中,我有一个变量$ topic的下拉列表,其值为"topic_A""topic_B"

In Grafana I have a drop down for variable $topic with values "topic_A" "topic_B"

选择了"topic_A",因此$ topic ="topic_A"

"topic_A" is selected so $topic = "topic_A"

我想使用以下方法查询普罗米修斯

I want to query prometheus using

function{topic=$topic}

那很好用.

我将如何实现

function{topic="$topic" + "_ERROR"}

(失败),如果选择"topic_A",我要查询的内容将是"topic_A_ERROR".

(this fails) where what I want to query would be "topic_A_ERROR" if "topic_A" is selected.

如何在查询中组合变量$ topic和字符串"_ERROR"?

How do I combine variable $topic and string "_ERROR" in the query?

推荐答案

更新2020-08-17:

Grafana变量有一种新语法,新格式是在美元符号后使用花括号:

There is a new syntax for Grafana variables, new format is to use curly braces after dollar sign:

function{topic=~"${topic}_ERROR"}

不建议使用双括号语法,并将很快删除.

Double brackets syntax is deprecated and will be deleted soon.

现在您还可以定义变量的格式,这可能有助于解决某些空间字符问题.示例:${topic:raw}

Also now you can define the format of the variable, which may help to solve some spacial characters issues. Example: ${topic:raw}

文档: https://grafana.com/docs/grafana/latest/variables/templates-and-variables/

如果要在中间包含文本,则需要使用其他语法:

If you want to include text in the middle you need to use a different syntax:

function{topic=~"[[topic]]_ERROR"}

不仅要注意双括号,还要注意从 = =〜的更改.它记录在我评论末尾的链接上,基本上说:

Note not only the double brackets but also the change from = to =~. It is documented on the link at the end of my comment, basically it says:

启用多值"或包含所有值"选项后,Grafana会将标签从纯文本转换为与regex兼容的字符串.这意味着您必须使用=〜而不是=.

When the Multi-value or Include all value options are enabled, Grafana converts the labels from plain text to a regex compatible string. Which means you have to use =~ instead of =.

您可以在此处查看官方说明: https://grafana.com/docs /grafana/latest/features/datasources/prometheus/#using-variables-in-queries

You can check the official explanation here: https://grafana.com/docs/grafana/latest/features/datasources/prometheus/#using-variables-in-queries

这篇关于将字符串追加到grafana查询中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆