简体   繁体   English

为什么在硬编码时Grafana ElasticSearch查询可以工作,但是在使用Grafana变量值替换时却失败? 以及如何解决?

[英]Why do Grafana ElasticSearch queries work when hard coded, but fail when using Grafana variable value substitution? and how to fix it?

问题图片

ElasticSearch query works when hard coded, but fails when using Grafana variable value substitution: ElasticSearch查询在进行硬编码时有效,但在使用Grafana变量值替换时失败:

Query: +nginx.access.upstream.response: [*, 1**, 2**, 3**, 4**, 5**, 500] 查询:+ nginx.access.upstream.response:[*,1 **,2 **,3 **,4 **,5 **,500]
Each of these queries work when you hard code those values in the query. 当您在查询中对这些值进行硬编码时,这些查询中的每一个都会起作用。

Example Query: +nginx.access.upstream.response: 1** 
               ^That works shows a table of data instead of "No data to show"

Although that works, it's better to use a variable with 7 values allows you to use 1 panel to display the same data that could be put in 7 hard coded panels, so that you end up with a cleaner user interface. 尽管这样做可以,但是最好使用具有7个值的变量,允许您使用1个面板来显示可以放入7个硬编码面板中的相同数据,从而最终获得更简洁的用户界面。

The problem is now that you've switched the hardcoded values to variable populated values the query no longer works. 现在的问题是,您已将硬编码值切换为变量填充值,查询不再起作用。
The plugged in variable values [* and 500] work 插入的变量值[*和500]有效
The plugged in variable values [1**, 2**, 3**, 4**, 5**] don't work / result in "No data to show" as seen above. 如上所示,插入的变量值[1 **,2 **,3 **,4 **,5 **]不起作用/导致“无数据显示”。

There's something funny going on when the values get substituted into the query. 当值被替换为查询时,会发生一些有趣的事情。
Q1.) What's the best tool/method to debug the true value of the variable after substitution/Figure out why it' failing? Q1。)在替换后找出变量真值的最佳工具/方法是什么/弄清楚为什么失败?
Q2.) What's a method of fixing it/achieving the desired end result? Q2。)有什么方法可以修复它/达到所需的最终结果?

Q1.) What's the best tool/method to debug the true value of the variable after substitution/Figure out why it' failing? Q1。)在替换后找出变量真值的最佳工具/方法是什么/弄清楚为什么失败?

Answer 1: Query Inspector 答案1:查询检查器
1** --when substituted becomes--> 1\\\\*\\\\* 1 **-当被替换时变为-> 1 \\\\ * \\\\ *
which explains why it didn't work 这解释了为什么它不起作用

A1。)查询检查器

Q2.) What's a method of fixing it/achieving the desired end result? Q2。)有什么方法可以修复它/达到所需的最终结果?

Answer 2: What worked for me was to avoid using the special character * in the variable values. 答案2:对我有用的是避免在变量值中使用特殊字符*。
I rename the variable to HTTP Code Prefix and used the values [*,1,2,3,4,5] 我将变量重命名为HTTP Code Prefix,并使用了值[*,1,2,3,4,5]
I then used the Query: +nginx.access.upstream.response: $http_code_prefix* 然后,我使用查询:+ nginx.access.upstream.response:$ http_code_prefix *

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

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