我是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上使用此表达式时,此表达式将起作用:
但是在普罗米修斯,它看起来像这样:
当内存使用量超过特定限制时,如何使我的警报发出警报?
答案 0 :(得分:1)
您的警报已正确配置为仅在查询结果连续3分钟高于3时发出警报。根据查询的Prometheus中的图表,它在过去一个小时内没有这样做,因此不会生成警报。
同样值得注意的是,您用于规则的查询将仅返回每个结果的实例标签。因此,如果您打算在警报中使用应用程序标签,则需要调整查询以也返回应用程序标签,或者将该标签添加到规则中添加的标签列表中。
答案 1 :(得分:1)
您要平均一段时间内的堆使用情况。我提出了以下建议:
- 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}}%`)"