Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Metric value in Alias?

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

like image 635
ROMANIA_engineer Avatar asked Aug 17 '16 09:08

ROMANIA_engineer


1 Answers

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.

like image 191
Bogdan Sahlean Avatar answered Sep 26 '22 08:09

Bogdan Sahlean