【问题标题】:Custom alert for pod memory utilisation in PrometheusPrometheus 中 pod 内存利用率的自定义警报
【发布时间】:2019-01-03 07:09:09
【问题描述】:

我在 Prometheus 中为 pod 内存使用情况创建了警报规则。警报在我的松弛频道上完美显示,但它不包含 pod 的名称,因此很难理解哪个 pod 有问题。

它只是显示[FIRING:35] (POD_MEMORY_HIGH_UTILIZATION default/k8s warning)。但是当我查看 Prometheus UI 中的“警报”部分时,我可以看到触发的规则及其 pod 名称。有人可以帮忙吗?

我的警报通知模板如下:

alertname: TargetDown
      alertname: POD_CPU_HIGH_UTILIZATION
      alertname:  POD_MEMORY_HIGH_UTILIZATION
receivers:

    - name: 'slack-notifications'

      slack_configs:

      - channel: '#devops'
        title: '{{ .CommonAnnotations.summary }}'
        text: '{{ .CommonAnnotations.description }}'

        send_resolved: true

我在警报通知模板中添加了选项title: '{{ .CommonAnnotations.summary }}' text: '{{ .CommonAnnotations.description }}',现在它显示了描述。我的描述是description: pod {{$labels.pod}} is using high memory。但只显示is using high memory。未指定 pod 名称

【问题讨论】:

  • 您将不得不分享从 Prometheus 到 Slack 的数据是如何共享的 - 没有它就很难回答这个问题
  • 我的告警通知模板如下: ---------------------------------- --- 路由:group_by:['job'] group_wait:1s group_interval:1m repeat_interval:12h 接收器:'slack-notifications' 路由:-匹配:alertname:POD_MEMORY_HIGH_UTILIZATION 接收器:-名称:'slack-notifications' slack_configs:-通道:'#devops' 标题:'{{ .CommonAnnotations.summary }}' 文本:'{{ .CommonAnnotations.description }}' send_resolved: true ------------------ -------------------
  • 我在警报通知模板中添加了选项“title: '{{ .CommonAnnotations.summary }}' text: '{{ .CommonAnnotations.description }}'”,现在它显示描述。我的描述是“描述:pod {{$labels.pod}} 正在使用高内存”。但只显示“正在使用高内存”。未指定 pod 名称。
  • 标签未预先填充,您必须在警报级别进行配置。您是否还可以添加有问题的这些额外信息 - 它会帮助其他人

标签: kubernetes prometheus-alertmanager


【解决方案1】:

article 中所述,您应该检查警报规则并在必要时更新它们。看一个例子:

ALERT ElasticacheCPUUtilisation
  IF aws_elasticache_cpuutilization_average > 80
  FOR 10m
  LABELS { severity = "warning" }
    ANNOTATIONS {
    summary = "ElastiCache CPU Utilisation Alert",
    description = "Elasticache CPU Usage has breach the threshold set (80%) on cluster id {{ $labels.cache_cluster_id }}, now at {{ $value }}%",
    runbook = "https://mywiki.com/ElasticacheCPUUtilisation",
  }

要为您的 prometheus GUI 提供外部 URL,请将 CLI 参数应用于您的 prometheus 服务器并重新启动它:

-web.external-url=http://externally-available-url:9090/

之后,您可以将这些值放入您的警报管理器配置中。看一个例子:

receivers:
  - name: 'iw-team-slack'
    slack_configs:
    - channel: alert-events
      send_resolved: true
      api_url: https://hooks.slack.com/services/<your_token>
      title: '[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] Monitoring Event Notification'
      text: >-
        {{ range .Alerts }}
           *Alert:* {{ .Annotations.summary }} - `{{ .Labels.severity }}`
          *Description:* {{ .Annotations.description }}
          *Graph:* <{{ .GeneratorURL }}|:chart_with_upwards_trend:> *Runbook:* <{{ .Annotations.runbook }}|:spiral_note_pad:>
          *Details:*
          {{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`
          {{ end }}
        {{ end }}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 2020-07-03
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 2019-02-18
    • 1970-01-01
    相关资源
    最近更新 更多