Hi to everyone!
How can i change the values results? for example:
Expressión: $C < 1
{{ $values.C.Value }}
i need to change value 1 and 0…
I need that when the value is less than 1 the word “Down” appears and when it is 1 or more, the value is “Up”
Thnks!
Hi @rodrigoparavano,
You can solve this problem on data source level (inside query) or on grafana level (using go template).
1. Data source level (query)
If you are using InfluxDB with Flux language you can use map
with if
condition like so:
|> map(fn: (r) => ({ r with state: if float(v: r._value) >= 1.0 then "up" else "down" }))
Full example query:
from(bucket: "test")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "net_response")
|> filter(fn: (r) => r["_field"] == "result_code")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> map(fn: (r) => ({ r with state: if float(v: r._value) >= 1.0 then "up" else "down" }))
|> drop(columns: ["_start", "_stop", "config", "server"])
|> group(columns: ["_measurement","_field", "host", "port", "protocol", "state"], mode:"by")
|> yield(name: "mean")
That would output data with new column state
which can have values up
or down
depending on value.
2. Grafana level (using go template)
You can also do it inside Grafana alert with go template. Instead of defining {{ $values.C.Value }}
you can use:
{{ if (ge $values.B.Value 1.0) }}up{{else}}down{{end}}
Full example Description message:
Hey! Port {{ $values.B.Labels.port }} has state {{ if (ge $values.B.Value 1.0) }}up{{else}}down{{end}} (default value is {{ $values.B.Value }}).
Alert config:
Best regards,
ldrascic