Add parameters in rules files expression

30 views
Skip to first unread message

inmar tzemach

unread,
Feb 27, 2023, 8:58:47 AM2/27/23
to Prometheus Users
Is it possible to add parameters in rules files expression?
Something like:
    expr: (100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)) > {{ $treshhold}}

Thanks

Brian Candler

unread,
Feb 27, 2023, 10:06:27 AM2/27/23
to Prometheus Users
No, but you can expand the rules files using a preprocessor of your choice.

If you want the threshold to be different for different time series, then see https://www.robustperception.io/using-time-series-as-alert-thresholds

inmar tzemach

unread,
Feb 28, 2023, 1:55:24 AM2/28/23
to Prometheus Users
Thanks!

How can I change the threshold from outside for giving expression while Prometheus running? 

Brian Candler

unread,
Feb 28, 2023, 3:31:12 AM2/28/23
to Prometheus Users
After changing the rules file, you'll need to trigger a prometheus reload, either by hitting a special API endpoint or sending it a SIGHUP. See https://prometheus.io/docs/prometheus/latest/management_api/#reload

(Note: *don't* restart the prometheus process! That's a much slower operation as it has to dump out and reload its WAL and can take several minutes on a busy server)

sayf.eddi...@gmail.com

unread,
Feb 28, 2023, 3:39:47 AM2/28/23
to Prometheus Users
FWIW, we use saltstack based jinja2 templating with a configured systemd reload (ExecReload=/bin/kill -HUP $MAINPID) to update the thresholds, and it works fine
Reply all
Reply to author
Forward
0 new messages