繁体   English   中英

如何使用Micrometer和Alertmanager在Prometheus中警告JVM内存使用情况

[英]How to alert on JVM memory usage in Prometheus with Micrometer and Alertmanager

我是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上使用此表达式时,该表达式有效:

Grafana示例

但是在普罗米修斯,它看起来像这样:

在普罗米修斯查询

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

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

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

您想要平均一段时间内的堆使用情况。 我想出了以下几点:

- 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}}%`)"

暂无
暂无

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

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