Grafana: Pie Chart: Unterschied zwischen den Versionen
Aus Wiki-WebPerfect
Admin (Diskussion | Beiträge) |
Admin (Diskussion | Beiträge) |
||
(7 dazwischenliegende Versionen des gleichen Benutzers werden nicht angezeigt) | |||
Zeile 4: | Zeile 4: | ||
== One Query -> multiple Pie slices (recommended) == | == One Query -> multiple Pie slices (recommended) == | ||
[[Datei:01-grafana pie-chart.png|right]] | [[Datei:01-grafana pie-chart.png|right]] | ||
− | ''This works only with Grafana 8.x or higher!'' | + | '''This works only with Grafana 8.x or higher!''' |
=== InfluxDB Flux Query === | === InfluxDB Flux Query === | ||
Zeile 14: | Zeile 14: | ||
measurement = "<YOUR_MEASUREMENT>" | measurement = "<YOUR_MEASUREMENT>" | ||
field = "<YOUR_FIELD>" | field = "<YOUR_FIELD>" | ||
− | group = "<YOUR_GROUP/YOUR_SLICES>" //in this examples the | + | group = "<YOUR_GROUP/YOUR_SLICES>" //in this examples the SLA |
from(bucket: bucket) | from(bucket: bucket) | ||
Zeile 29: | Zeile 29: | ||
|> rename(columns: {_value: ""}) //remove _value from Pie slice naming | |> rename(columns: {_value: ""}) //remove _value from Pie slice naming | ||
</pre> | </pre> | ||
+ | |||
+ | '''Tipp:''' Instead of using the rename at the end of the query above, use Grafanas "Display Name". More information's: [[Grafana: Alias by (Display name)]] | ||
+ | |||
+ | |||
+ | |||
+ | == Multiple Queries -> multiple Pie slices == | ||
+ | [[Datei:02-grafana pie-chart.png|right]] | ||
+ | '''This works also before Grafana 8.x. Add multiple Queries in the Grafana panel:''' <br> | ||
+ | [[Datei:03-grafana pie-chart.png]] | ||
+ | |||
+ | === InfluxDB Flux A-Query (for Category-1) === | ||
+ | <pre> | ||
+ | //define variables | ||
+ | bucket = "<YOUR_BUCKET>" | ||
+ | measurement = "<YOUR_MEASUREMENT>" | ||
+ | field = "<YOUR_FIELD>" | ||
+ | |||
+ | from(bucket: bucket) | ||
+ | |> range(start: v.timeRangeStart, stop: v.timeRangeStop) | ||
+ | |> filter(fn: (r) => | ||
+ | r._measurement == measurement and | ||
+ | r._field == field | ||
+ | ) | ||
+ | |> last() | ||
+ | |> group() | ||
+ | |> keep(columns: ["host"]) | ||
+ | |> distinct(column: "host") | ||
+ | |> count() | ||
+ | |> rename(columns: {_value: "Category-1"}) | ||
+ | </pre> | ||
+ | |||
+ | === InfluxDB Flux B-Query (for Category-2) === | ||
+ | <pre> | ||
+ | //define variables | ||
+ | bucket = "<YOUR_BUCKET>" | ||
+ | measurement = "<YOUR_MEASUREMENT>" | ||
+ | field = "<YOUR_FIELD>" | ||
+ | |||
+ | from(bucket: bucket) | ||
+ | |> range(start: v.timeRangeStart, stop: v.timeRangeStop) | ||
+ | |> filter(fn: (r) => | ||
+ | r._measurement == measurement and | ||
+ | r._field == field | ||
+ | ) | ||
+ | |> last() | ||
+ | |> group() | ||
+ | |> keep(columns: ["host"]) | ||
+ | |> distinct(column: "host") | ||
+ | |> count() | ||
+ | |> rename(columns: {_value: "Category-2"}) | ||
+ | </pre> | ||
+ | |||
+ | |||
Aktuelle Version vom 11. Februar 2022, 10:14 Uhr
Following are two examples to make great Pie Chart with Grafana and InfluxDB Flux.
Inhaltsverzeichnis
One Query -> multiple Pie slices (recommended)
This works only with Grafana 8.x or higher!
InfluxDB Flux Query
Create a Grafana Pie chart panel that shows the count of unique hosts per SLA. We named the SLA's (in Influx tag "sla") as precious metals for example "Gold".
//define variables bucket = "<YOUR_BUCKET>" measurement = "<YOUR_MEASUREMENT>" field = "<YOUR_FIELD>" group = "<YOUR_GROUP/YOUR_SLICES>" //in this examples the SLA from(bucket: bucket) |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r._measurement == measurement and r._field == field ) |> last() |> group() |> unique(column: "host") |> group(columns: ["sla"]) |> count() |> rename(columns: {_value: ""}) //remove _value from Pie slice naming
Tipp: Instead of using the rename at the end of the query above, use Grafanas "Display Name". More information's: Grafana: Alias by (Display name)
Multiple Queries -> multiple Pie slices
This works also before Grafana 8.x. Add multiple Queries in the Grafana panel:
InfluxDB Flux A-Query (for Category-1)
//define variables bucket = "<YOUR_BUCKET>" measurement = "<YOUR_MEASUREMENT>" field = "<YOUR_FIELD>" from(bucket: bucket) |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r._measurement == measurement and r._field == field ) |> last() |> group() |> keep(columns: ["host"]) |> distinct(column: "host") |> count() |> rename(columns: {_value: "Category-1"})
InfluxDB Flux B-Query (for Category-2)
//define variables bucket = "<YOUR_BUCKET>" measurement = "<YOUR_MEASUREMENT>" field = "<YOUR_FIELD>" from(bucket: bucket) |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r._measurement == measurement and r._field == field ) |> last() |> group() |> keep(columns: ["host"]) |> distinct(column: "host") |> count() |> rename(columns: {_value: "Category-2"})