如何使用测微计和Alertmanager对Prometheus中的JVM内存使用情况发出警报

如何使用测微计和Alertmanager对Prometheus中的JVM内存使用情况发出警报,jvm,alert,prometheus,micrometer,Jvm,Alert,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="he

我不熟悉普罗米修斯和千分尺。我试图在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上使用此表达式时,此表达式起作用:

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


如何使我的警报在内存使用超过某个限制时发出警报?

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


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

您希望计算一段时间内堆使用率的平均值。我得出了以下结论:

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

我知道它在连续5分钟内不会超过3,因为它在普罗米修斯有一个锯状的度量。但是怎么能只看到锯子的顶端呢?为什么格拉法纳有一个稳定的百分比?它质疑普罗米修斯有不同的方式吗?关于实例标签,您的意思是在描述中使用“{$labels.instance}}”?如何返回标签?Grafana显示稳定的百分比只是因为您正在显示timeseries中的最新值,因为它是一个singlestat面板。如果将图形面板用于该查询,您将看到相同的结果。