Grafana: Alias by (Display name): Unterschied zwischen den Versionen

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche
Zeile 1: Zeile 1:
 
[[Datei:01-grafana alias-by.png|right]]
 
[[Datei:01-grafana alias-by.png|right]]
If you use a InfluxDB datasource with Query Language = InfluxQL, in a Grafana panel there was an option '''ALIAS BY'''. <br>
+
If you use a '''InfluxDB datasource with Query Language = InfluxQL''', in a Grafana panel there was an option '''ALIAS BY'''. <br>
 
This option is missing when you use a InfluxDB datasource with Query Language = Flux! <br>
 
This option is missing when you use a InfluxDB datasource with Query Language = Flux! <br>
In this article I show you how you can format the naming like with ''ALIAS BY'' but with Flux.
+
In this article I show you how you can change the naming like with ''ALIAS BY'' but with Flux.
  
 +
== Change naming like ''ALIAS BY'' with map() ==
 +
In this example we want following naming (like the image to the right): '''<Description> - <Hostname>: <VMName>''' <br>
 +
*'''Description''' = Hardcoded description of the measurement "CPU Load Total"
 +
*'''Hostname''' = InfluxDB Tag "host"
 +
*'''VMName''' = InfluxDB Tag "VMName"
 +
 +
 +
<pre>
 +
..<YOUR_FLUX_QUERY>..
 +
|> map(fn: (r) => ({ r with
 +
  display_name: "CPU Load Total - " + r.host + ":" + r.VMName})
 +
  )
 +
|> group(columns: ["display_name"])
 +
 +
 +
 +
 +
 +
</pre>
  
  

Version vom 8. September 2021, 10:08 Uhr

01-grafana alias-by.png

If you use a InfluxDB datasource with Query Language = InfluxQL, in a Grafana panel there was an option ALIAS BY.
This option is missing when you use a InfluxDB datasource with Query Language = Flux!
In this article I show you how you can change the naming like with ALIAS BY but with Flux.

Change naming like ALIAS BY with map()

In this example we want following naming (like the image to the right): <Description> - <Hostname>: <VMName>

  • Description = Hardcoded description of the measurement "CPU Load Total"
  • Hostname = InfluxDB Tag "host"
  • VMName = InfluxDB Tag "VMName"


..<YOUR_FLUX_QUERY>..
|> map(fn: (r) => ({ r with 
  display_name: "CPU Load Total - " + r.host + ":" + r.VMName})
  )
|> group(columns: ["display_name"])