How to add node_filesystem_avail_bytes metric value to description grafana?

Hello, I’m having a problem. When I set up alert rules in prometheus, I had a disk space monitoring rule that showed me the percentage of remaining space and humanize the value of the node_filesystem_avail_bytes metric.

Now my rule looks like this:

  • alert: HostOutOfDiskSpace_test
    expr: (node_filesystem_avail_bytes * 100) / node_filesystem_size_bytes > 0 and ON (instance, device, mountpoint) node_filesystem_readonly == 0 and {instance=~“10.22.22.18.*”}
    for: 1s
    labels:
    severity: high
    annotations:
    summary: “Host {{ $labels.instance }} out of memory \n - Device: {{ $labels.device }} \n - Mountpoint - {{ $labels.mountpoint }}”
    description: “Node memory is filling up. Value = {{ $value | printf %.2f }} ({{ printf "node_filesystem_avail_bytes{mountpoint=‘%s’, instance=‘%s’}" .Labels.mountpoint .Labels.instance | query | first | value | humanize1024 }})”

Here are examples of notifications from telegrams:

:fire: [PROBLEM] HostOutOfDiskSpace_test_1
Severity: high
Summary: Host 10.11.11.100:9100 out of memory
- Device: /dev/sda1
- Mountpoint - /boot
Description: Node memory is filling up. Value = 72.62 (736.4Mi)
Starts at: 2023-08-31 13:19:52.25 +0300 EAT

When I try to transfer this description to grafana, it outputs it as text.
:fire: [PROBLEM] Test_grafana_rules_filesystem
Severity: high
Summary: Host 10.11.11.100:9100 out of memory
- Device: /dev/sda1
- Mountpoint - /boot
Description: Node memory is filling up. Value = 72.61% ({{ printf "node_filesystem_avail_bytes{mountpoint=‘%s’, instance=‘%s’}" .Labels.mountpoint .Labels.instance | query | first | value | humanize1024 }})
Starts at: 2023-08-31 13:22:49.12 +0300 EAT

My question is this. How can I display the actual values ​​of the value of the node_filesystem_avail_bytes metric in description grafana?


Unfortunately, querying from the template is not supported in Grafana Alerting. You need to rewrite the query and provide the raw value (in Mi) then use threshold expression to determine normal\alerting, and format the raw value in the annotation.

Also, try to use Instant query as it is cheaper and does not require the reduce expression (B).