Getting the dynamic threshold to print in the alert.

27 views
Skip to first unread message

Yagyansh S. Kumar

unread,
Mar 13, 2020, 8:55:34 AM3/13/20
to Prometheus Users
Hi. I am using Number of Cores of a server as the threshold for CPU Load. It is working fine but I want to print the number of cores also in the alert.

Configured Alert:

  - alert: HighCpuLoad
    expr: (node_load15 > count without (cpu, mode) (node_cpu_seconds_total{mode="system"})) * on(instance) group_left(nodename) node_uname_info
    for: 5m
    labels:
      severity: "CRITICAL"
    annotations:
      summary: "CPU load on {{ $labels.instance }} - {{ $labels.nodename }} is more than number of cores of the machine."
      description: "Current Value = {{ $value | humanize }}"

Instead of the string "number of cores of the machine ", I want to actual number of cores of the server. Is there any way to do this?

Thanks!

Christian Hoffmann

unread,
Mar 14, 2020, 7:37:19 AM3/14/20
to Yagyansh S. Kumar, Prometheus Users
Hi,

On 3/13/20 1:55 PM, Yagyansh S. Kumar wrote:
> Hi. I am using Number of Cores of a server as the threshold for CPU
> Load. It is working fine but I want to print the number of cores also in
> the alert.
>
> Configured Alert:
>
>   - alert: HighCpuLoad
>     expr: (node_load15 > count without (cpu, mode)
> (node_cpu_seconds_total{mode="system"})) * on(instance)
> group_left(nodename) node_uname_info
>     for: 5m
>     labels:
>       severity: "CRITICAL"
>     annotations:
>       summary: "CPU load on {{ $labels.instance }} - {{ $labels.nodename
> }} is more than *number of cores of the machine*."
>       description: "Current Value = {{ $value | humanize }}"
>
> Instead of the string "*number of cores of the machine* ", I want to
> actual number of cores of the server. Is there any way to do this?

Yes, you should be able to query the TSDB using in your summary template
string.

See this for examples:

https://prometheus.io/docs/prometheus/latest/configuration/template_examples/

Kind regards,
Christian

Yagyansh S. Kumar

unread,
Mar 14, 2020, 11:23:15 AM3/14/20
to Prometheus Users
Thanks for the help. Will try this.
Reply all
Reply to author
Forward
0 new messages