Prometheus format alarm value

Prometheus can use $valuevariables to output the value of the current alarm rule expression into the alarm information. But some floating-point values ​​are quite long, which is very difficult to read, and it is even more unacceptable for patients with obsessive-compulsive disorder. How to make the alarm value "human readable"?
There are the following alarm rules to detect a certain domain name and send an alarm if the access time exceeds 0.5 seconds and lasts for more than 1 minute:

- name: blackbox-exporter
    rules:
    - alert: DomainAccessDelayExceeds0.5s
      annotations:
        description: 域名:{
    
    {
    
     $labels.instance }} 探测延迟大于 0.5 秒,当前延迟为:{
    
    {
    
     $value }}
        summary: 域名探测,访问延迟超过 0.5 秒
      expr: sum(probe_http_duration_seconds{
    
    job=~"blackbox"}) by (instance) > 0.5
      for: 1m
      labels:
        severity: warning
        type: blackbox

When the traffic exceeds 0.5s, an alarm notification is triggered.

[1] Firing
Labels
alertname = DomainAccessDelayExceeds0.5s
instance = https://www.baidu.com
prometheus = monitoring/k8s
severity = warning
type = blackbox

Annotations
description = 域名:https://www.baidu.com 探测延迟大于 0.5 秒,当前延迟为:1.042937559
summary = 域名探测,访问延迟超过 0.5 秒

In the received alarm notification information, you can see that the delay time is up to 9 digits after the decimal point

There are three ways to format the value of the variable in the alarm rule $value:

{
   
   { printf "%.2f" $value }}
或
{
   
   { $value | printf "%.2f" }}
或
{
   
   { humanize $value }}

After testing { { printf "%.2f" $value }}or { { $value | printf "%.2f" }}adjustment, the alarm notification information received only has two decimal places; { { humanize $value }}it is three decimal places (for example: 1.262), or displayed as milliseconds (for example: 686.2m)

Guess you like

Origin blog.csdn.net/zyy247796143/article/details/130605030
Recommended