【问题标题】:How to alert on JVM memory usage in Prometheus with Micrometer and Alertmanager如何使用 Micrometer 和 Alertmanager 在 Prometheus 中提醒 JVM 内存使用情况
【发布时间】:2019-03-31 04:12:09
【问题描述】:

我是 Prometheus 和 Micrometer 的新手。我试图在 JVM 的堆内存使用量超过某个阈值时发出警报。

- alert: P1 - Percentage of heap memory usage on environment more than 3% for 5 minutes.
    expr: sum(jvm_memory_used_bytes{application="x", area="heap"})*100/sum(jvm_memory_max_bytes{application="x", area="heap"}) by (instance) > 3
    for: 5m
    labels:
      priority: P1
      tags: infrastructure, jvm, memory
    annotations:
      summary: "Percentage of heap memory is more than threshold"
      description: "Percentage of heap memory for instance '{{ $labels.instance }}' has been more than 3% ({{ $value }}) for 5 minutes."

现在当我在 Grafana 上使用这个表达式时,这个表达式可以工作了:

但在 Prometheus 中是这样的:

如何让我的警报在内存使用量超过特定限制时发出警报?

【问题讨论】:

    标签: jvm alert prometheus micrometer


    【解决方案1】:

    您的警报已正确配置为仅在查询结果连续 5 分钟高于 3 时才发出警报。根据查询的 Prometheus 中的图表,它在过去一小时内没有这样做,因此没有生成警报。

    同样值得注意的是,您用于规则的查询只会返回每个结果的实例标签。因此,如果您计划在警报中使用应用程序标签,则需要调整查询以同时返回应用程序标签,或者将该标签添加到规则中添加的标签列表中。

    【讨论】:

    • 我知道它连续 5 分钟不超过 3,因为它在 prometheus 中具有类似锯齿的度量。但是怎么可能只拿锯子的山峰呢?为什么 Grafana 的百分比很稳定?它查询普罗米修斯有不同的方式吗?关于实例标签,您的意思是在描述中使用“{{ $labels.instance }}”吗?我将如何退回标签?
    • Grafana 显示稳定的百分比只是因为您显示的是时间序列中的最新值,因为它是一个单统计面板。如果您要对该查询使用图形面板,您会看到相同的内容。
    【解决方案2】:

    您希望随时间平均堆使用量。我想出了以下几点:

    - name: jvm
      rules:
        - alert: jvm_heap_warning
          expr: sum(avg_over_time(jvm_memory_used_bytes{area="heap"}[1m]))by(application,instance)*100/sum(avg_over_time(jvm_memory_max_bytes{area="heap"}[1m]))by(application,instance) >= 80
            for: 1m
            labels:
              severity: warning
            annotations:
              summary: "JVM heap warning"
              description: "JVM heap of instance `{{$labels.instance}}` from application `{{$labels.application}}` is above 80% for one minute. (current=`{{$value}}%`)"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-10
      • 1970-01-01
      • 2021-05-09
      • 2019-07-18
      • 2013-05-17
      • 2015-01-08
      • 1970-01-01
      相关资源
      最近更新 更多