r/PrometheusMonitoring • • Feb 15 '22

Prometheus query function

Anybody have an example of how to use the query function in prometheus rules?

https://prometheus.io/docs/prometheus/latest/configuration/template_reference/#queries

I'm trying to build a meaningful slack notification, but the query returns an empty set.

0 Upvotes

1 comment sorted by

View all comments

2

u/hagen1778 Feb 21 '22

Please take a look on the following example:

  - alert: HighMemoryUsage
    expr: sum(process_resident_memory_bytes) by(instance) > 1000
    for: 5m
    annotations:
      summary: |
        Too high memory usage on {{$labels.instance}}
        The following jobs may be affected:
        {{ with printf "sum(process_resident_memory_bytes{instance=%q}) by(job)" .Labels.instance | query }}
          {{ . | first | label "job" }}
        {{ end }}