Grafana中Influx模板查询:含$的标签键如何转义避免变量插值
Got it, I’ve run into this exact headache before—dealing with InfluxDB tag keys that include dollar signs when using Grafana’s templating. The fix is straightforward once you know Grafana’s escape syntax for literal dollar signs.
Grafana’s template engine treats a single $ as the start of a variable interpolation. To tell it to treat the $ as a literal character (part of your tag key, not a variable), you just need to double the dollar sign ($$).
Modified Query
Here’s your adjusted query that will preserve the $owner part of the tag key instead of trying to interpolate it:
SHOW TAG VALUES FROM "exdemon-analysis" WITH KEY = "analyzed_metric.attributes.$$owner"
Why This Works
Grafana’s templating parser will replace $$ with a single literal $ when sending the query to InfluxDB. So the final query that hits your InfluxDB instance will be exactly what you need:
SHOW TAG VALUES FROM "exdemon-analysis" WITH KEY = "analyzed_metric.attributes.$owner"
This trick works for any scenario where you need a literal $ in your query without Grafana trying to substitute a variable. Just replace every single $ you want to keep with $$.
内容的提问来源于stack exchange,提问作者DLanza

