prometheus / alertmanager

Prometheus Alertmanager
https://prometheus.io
Apache License 2.0
6.64k stars 2.15k forks source link

How can I get a week's worth of alert history for Prometheus, Alertmanager via python script? #3779

Closed wudongwang closed 7 months ago

wudongwang commented 7 months ago

How can I get a week's worth of alert history for Prometheus, Alertmanager via python script?

TheMeier commented 7 months ago

Hi @wudongwang,

this question would be better posted at https://groups.google.com/g/prometheus-users or a similar forum. The issue tracker is not the right place.

Apart from that, there is two things that come to mind immediately. a) If your prometheus retention is long enough query for active alerts in promql, see https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/#inspecting-alerts-during-runtime b) send all alerts via webhook to a service that persists these events. For example with this webhook-adapter https://github.com/cloudflare/alertmanager2es you can send all alerts to elasticsearch and then visualize them in kibana.

wudongwang commented 7 months ago

已通过查询表达式获取到数据:ALERTS_FOR_STATE:firing[1d]