Ah, good points. Thanks a bunch

On Sunday, June 23, 2024 at 2:57:40 AM UTC-7 Brian Candler wrote:

> node_cpu_seconds_total gives you a separate metric for each CPU, so with 
> an 8 vCPU VM you'll get 8 alerts (if they're all under 20%)
>
> You're saying that you're happy with all these alerts, but want to 
> suppress them where the VM has only one vCPU?  In that case:
>
>     count by (instance) (node_cpu_seconds_total{mode="idle"})
>
> will give you the number of CPUs per instance, and hence you can modify 
> your alert to something like
>
>     expr: ( ......... unless on (instance) count by (instance) 
> (node_cpu_seconds_total{mode="idle"} == 1)
>
> which would give something like:
>
>   (
>
>       (100 - (rate(node_cpu_seconds_total{mode="idle"}[30m]) * 100) < 20)
>     unless on (instance)
>       count by (instance) (node_cpu_seconds_total{mode="idle"} == 1)
>   )
> * on (instance) group_left (nodename)
>   node_uname_info{nodename=~".+"}
>
> Aside 1: personally I like to leave percentages as fractions. You can 
> change these to percentages in alerts using humanizePercentage 
> <https://prometheus.io/docs/prometheus/latest/configuration/template_reference/#numbers>
>
> Aside 2: It might be better to aggregate all the CPUs usage for an 
> instance. Otherwise, if you have 8 mostly-idle CPUs, but each CPU in turn 
> has a short burst of activity, you'll get no alerts.  Do do this, you 
> should use sum over rate 
> <https://www.robustperception.io/rate-then-sum-never-sum-then-rate/>, not 
> rate over sum.
>
> On Saturday 22 June 2024 at 17:01:58 UTC+1 mel wrote:
>
>> I have this CPU underutilized alert for virtual machines.
>>
>> expr: '(100 - (rate(node_cpu_seconds_total{mode="idle"}[30m]) * 100) < 
>> 20) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
>>
>> for: 1w
>>
>> The problem is that I get alerted even if the CPU is 1 so I cannot reduce 
>> it further. I want the alert to fire only number of CPUs > 1.
>>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/6524d685-8f67-4595-8bfa-ee1122f0b911n%40googlegroups.com.

Reply via email to