Hi @rodrigoparavano,
If you want to get label value from query then you can do with:
{{ $values.<queryname>.Labels.<tag> }}
For example:
On server {{ $values.B.Labels.host }} port {{ $values.B.Labels.port }} is closed (not listening).
would print:
On server monitoringserver port 8282 is closed (not listening).
Bonus:
Dynamic Severity labels
You can also do more advanced stuff like dynamic label value setting based on query values. For example you can set custom label Severity which would have next values:
Fatal for values >= 98
Critical for values >= 95 AND < 98
Warning for values >= 90 AND < 95
NoData if $value.B does not exist
Severity label formula:
{{ if $values.result }}{{ if (ge $values.result.Value 98.0) }}Fatal{{ else if and (lt $values.result.Value 98.0) (ge $values.result.Value 90.0) }}Critical{{ else if and (lt $values.result.Value 90.0) (ge $values.result.Value 85.0) }}Warning{{ else }}None{{ end }}{{ else }}NoData{{ end }}
Note that here my query in grafana alert is called result. Be aware that every time new severity label is created (for example Severity=Critical) a new alert check will be created and the alert with old Severity label (e.g. Severity=Warning) will be resolved with "grafana_state_reason": "MissingSeries"
. Newly created check would first go to pending (if you set it) and then to alerting state.
In order to avoid quick changes of Severity label (and thus avoiding alerts being in pending mode) I usually use mean function in my query with time range of 5 minutes (mean of values over larger time range provides more stable number but it is slower at alerting). Also, I always first round numbers (with Math expression) and then perform Threshold expression over rounded numbers. Reason behind is also to avoid fast label changing.
Last thing to mention is part of formula which checks if data in result variable exists:
{{ if $values.result }}........{{ else }}NoData{{ end }}
This is used so that when data is missing (e.g. agent has crashed or somebody stopped it) you get Severity=NoData instead of broken formula like on next picture:
Hope this helps.
Best regards,
ldrascic