简体   繁体   English

普罗米修斯警报中缺少标签

[英]Missing labels in prometheus alerts

I'm having issues with Prometheus alerting rules.我在使用 Prometheus 警报规则时遇到问题。 I have various cAdvisor specific alerts set up, for example:我设置了各种 cAdvisor 特定警报,例如:

- alert: ContainerCpuUsage
  expr: (sum(rate(container_cpu_usage_seconds_total[3m])) BY (instance, name) * 100) > 80
  for: 2m
  labels:
    severity: warning
  annotations:
    title: 'Container CPU usage (instance {{ $labels.instance }})'
    description: 'Container CPU usage is above 80%\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}'

When the condition is met, I can see the alert in the "Alerts" tab in Prometheus, however some labels are missing thus not allowing alertmanager to send a notification via Slack.满足条件时,我可以在 Prometheus 的“警报”选项卡中看到警报,但是缺少一些标签,因此不允许警报管理器通过 Slack 发送通知。 To be specific, I attach custom "env" label to each target:具体来说,我将自定义“env” label 附加到每个目标:

 {
  "targets": [
   "localhost:8080",
  ],
  "labels": {
   "job": "cadvisor",
   "env": "production",
   "__metrics_path__": "/metrics"
  }
 }

But when the alert based on cadvisor metrics is firing, the labels are: alertname, instance and severity - no job label, no env label.但是当基于 cadvisor 指标的警报触发时,标签是:警报名称、实例和严重性 - 没有作业 label,没有环境 label。 All the other alerts from other exporters (fe node-exporter) work just fine and the label is present.来自其他出口商(fe node-exporter)的所有其他警报都可以正常工作,并且存在 label。

This is due to sum function that you use;这是由于您使用的sum function ; it gathered all the time series present and added them groping BY (instance, name) .它收集了所有存在的时间序列,并将它们添加到BY (instance, name)中。 If you run the same query in Prometheus, you'll see that sum left only grouping labels:如果您在 Prometheus 中运行相同的查询,您会看到sum只剩下分组标签:

{instance="foo", name="bar"}    135.38819037447163

Other aggregation methods like avg , max , min , etc, work in the same fashion.其他聚合方法,如avgmaxmin等,以相同的方式工作。 To bring the label back simply add env to the grouping list: by (instance, name, env) .要恢复 label,只需将env添加到分组列表中: by (instance, name, env)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM