How to use Metric value in Alias?

Elrond_EGLDer picture Elrond_EGLDer · Aug 17, 2016 · Viewed 22.3k times · Source

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)?

Answer

Bogdan Sahlean picture Bogdan Sahlean · Jul 20, 2017

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.