Per-host thresholds in prometheus alert

151 views
Skip to first unread message

Andrew Kulikov

unread,
Feb 26, 2021, 9:16:10 AM2/26/21
to Prometheus Users
Hi,

I have, for example, simple alert for low swap:

name: Low swap
expr: swap_used_percent > 80
for: 10m
labels:
    severity: warning
annotations:
    description: Swap usage is {{ $value | printf "%.2f" }}% on {{ $labels.host }}
    summary: Low swap


For some hosts it's normal to use 50% of swap, for other hosts -- 90% of swap. And I would like to define different thresholds for different hosts. Can I define per-host threshold for swap usage write alert expression like this?

expr: swap_used_percent > {{ $swap_threshold }}

Thanks a lot!

David Leadbeater

unread,
Feb 26, 2021, 9:18:39 AM2/26/21
to Andrew Kulikov, Prometheus Users

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/13a55334-4548-4e03-b78e-56154fb6b4e1n%40googlegroups.com.

Stuart Clark

unread,
Feb 26, 2021, 9:39:15 AM2/26/21
to David Leadbeater, Andrew Kulikov, Prometheus Users
On 26/02/2021 14:18, David Leadbeater wrote:

On Fri, 26 Feb 2021 at 14:16, Andrew Kulikov <andrew....@gmail.com> wrote:
Hi,

I have, for example, simple alert for low swap:

name: Low swap
expr: swap_used_percent > 80
for: 10m
labels:
    severity: warning
annotations:
    description: Swap usage is {{ $value | printf "%.2f" }}% on {{ $labels.host }}
    summary: Low swap


For some hosts it's normal to use 50% of swap, for other hosts -- 90% of swap. And I would like to define different thresholds for different hosts. Can I define per-host threshold for swap usage write alert expression like this?

expr: swap_used_percent > {{ $swap_threshold }}

Alternatively instead of comparing against a fixed threshold (which needs periodic checks & adjustment) you can use the predict_linear function (https://prometheus.io/docs/prometheus/latest/querying/functions/#predict_linear) to project how long until all swap is used based on recent usage increases.

-- 
Stuart Clark
Reply all
Reply to author
Forward
0 new messages