Prometheus - 注释下的表达式

Prometheus - Expression under annotations

我想发送如下所示的电子邮件提醒(我有一个自定义模板):

描述 = 磁盘几乎已满:< 20% 剩余

Summary = Volume D: on 192.168.1.10 - Windows Server Disk Space Usage
Size = 200Gi
Used = 180Gi
Available = 20Gi

到目前为止我有:

alert: 'WARNING - Host out of Disk Space'
expr: 100.0 - 100 * ((windows_logical_disk_free_bytes / 1024 / 1024 ) / (windows_logical_disk_size_bytes / 1024 / 1024)) > 80
for: 1m
labels:
  severity: warning
annotations:
  Summary: "Volume {{ $labels.volume }} on {{ $labels.instance }} - Windows Server Disk Space Usage"
  Description: "Disk is almost full: < 20% left)"
  Size: "{{ printf \"windows_logical_disk_size_bytes{volume='%s'}\" .Labels.volume | query | first | value | humanize1024 }}"
  Used: "{{ printf \"windows_logical_disk_free_bytes{volume='%s'}\" .Labels.volume | query | first | value | humanize1024 }}"
  Available: ???

我已经尝试了几个“可用”选项,但其中 none 有效。我得到 'error expanding template'。 我基本上想要这个查询 => (windows_logical_disk_size_bytes{volume='%s'} - windows_logical_disk_free_bytes{volume='%s'})

正确的做法是什么?任何帮助将不胜感激。

首先:“已用”和“可用”的正确表达方式如下,对吗?

Used:      windows_logical_disk_size_bytes - windows_logical_disk_free_bytes
Available: windows_logical_disk_free_bytes

回答您的问题:

我认为你不能在警报模板中使用表达式,那么你需要像下面这样定义一个“记录规则”:

  - name: recording_rules
    rules:
      - record: windows_filesystem_used
        expr: windows_logical_disk_size_bytes - windows_logical_disk_free_bytes

在 Prometheus 文档中查看更多信息 here