簡體   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