How to use Metric value in Alias?
Asked Answered
D

2

7

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

Add Panel Graph

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

  • when it is 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 (E.g.: host) in Tags, I can use $tag_<key> (E.g.: $tag_host) in Alias.

I want to achieve the same behavior for the hard-coded Metric value (E.g.: xyz), such that if someone wants to change the Metric value in the future from xyz to abc, the Alias should be updated automatically.

I tried to use:

  • $metric
  • $Metric
  • $tag_metric

but they didn't work.

Grafana Metrics

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

Dictograph answered 17/8, 2016 at 9:4 Comment(3)
Do you see the metric value being changed at all after your dashboard is created? If the metric value is constant, then the alias can have the name of the metric as part of the alias.Mcconaghy
@Mcconaghy , I edited the post. The Metric value is a constant (xyz) per graph (I have many values in different graphs from the same dashboard). I know that I can use the same value in Alias as Label xyz $tag_host, but I would like to use something like Label $metric $tag_host instead, to be sure that it works even if someone changes only the Metric value after a while.Dictograph
What you want to achieve is not possible. The alias is a CONSTANT not a VARIABLE. We use alias in order to overwrite the default metric name, so even if you change the metric name, the alias should remain the same. If you want your alias to have the same name as your metric, the only solution to this is hardcoded. Just type xyz $tag_host in your alias. If anyone wan't to change the name of the metric, it should also change the name of the alias also.Ventricular
M
5

My solution: I included second tag (first one was id - $tag_id) into GROUP BY (tag(sql)) and then I used $tag_sql ($tag_key) variable to define alias for current series of data thus:

enter image description here

enter image description here Highlighted fields are tags.

Michel answered 20/7, 2017 at 19:1 Comment(2)
Note: I'm using grafana.4.4.1Michel
Tags in InfluxDB are a limited resources - we just ran into the 100k limit because we were using this approach to alias batch tasks. So be sure that you know your InfluxDB limits, and that you have a retention policy to clean up old tags in place.Dune
P
0

This might be a XY Problem.

If what you're trying to do is just to show the value in the Label, you don't need to create an alias. Just go to Legend and tick the appropriate option(s) (Min, Max, Avg, etc.). This will add a new column(s) near the Label with the appropriate value.

enter image description here

I'm using Grafana 4.4.3.

Phoenix answered 20/10, 2017 at 12:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.