How to use metric value in an alias?

I created a new Graph in Grafana that takes data from OpenTSDB.

Add Panel Chart

The Alias field has the following meaning: Label $metric $tag_host .

  • when interpreted, it looks like this:

    • Label $metric myhost1
    • ...
    • Label $metric myhostn
  • but I want to look like this:

    • Label xyz myhost1
    • ...
    • Label xyz myhostn where xyz is the value of the Metric field.

So, for a key (for example: host ) in tags, I can use $tag_<key> (for example: $tag_host ) in Alias ​​.. p>

I want to achieve the same behavior for a hard-coded Metric value (for example: xyz ), so if someone wants to change the Metric value in the future from xyz to abc , the alias should be automatically updated.

I tried using:

  • $metric
  • $metric
  • $tag_metric

but they did not work.

Grafana metrics

Is it possible to use the Metric value in Alias ​​without hard coding in Alias ​​(enough hard coding from Metric)?

+6
source share
2 answers

My solution: I included the second tag (the first was id - $tag_id ) in GROUP BY ( tag(sql) ), and then I used the variable $tag_sql ( $tag_key ) to define an alias for the current data series this way:

enter image description here

enter image description here Highlighted fields are tags.

+2
source

This may be an XY problem.

If what you are trying to do is just show the value in a shortcut, you do not need to create an alias. Just go to the "Legend" and check the appropriate options (min., Max., Average, etc.). This will add a new column next to the label with the corresponding value.

enter image description here

I am using Grafana 4.4.3.

0
source

All Articles