如何在Prometheus v2(2.2.1)中删除告警时间序列?原API已失效
Hey there, let's break down why your old API call stopped working and how to fix this:
Why the old method fails in Prometheus 2.x
Prometheus 2.x completely reworked how alerts are handled compared to 1.8. In 1.8, ALERTS was a pseudo-time-series stored in the TSDB, so you could delete it via the /api/v1/series endpoint. But in 2.x, ALERTS is a dynamically generated metric based on the current state of your alert rules—it's not persisted as a time-series in the database anymore. That's why you're getting the not implemented error: the delete endpoint doesn't apply to these dynamic metrics.
Fixes to clean old alerts
Here are the practical solutions based on your use case:
1. Let Prometheus auto-clean old resolved alerts
Prometheus automatically removes resolved alerts from its active state after a short window (tied to your alert rule's for duration and TSDB retention settings). To adjust how long historical alert data is kept:
- Edit your
prometheus.ymlconfig or start Prometheus with the flag--storage.tsdb.retention.time(default is 15d). For example:
This will automatically purge old time-series data, which in turn cleans up the associated alert history once the data expires.prometheus --storage.tsdb.retention.time=7d
2. Force immediate cleanup of all alert states (for testing/emergencies)
If you need to clear all old alerts right away, the simplest method is to restart Prometheus. When it boots back up, it re-evaluates all alert rules from scratch—only alerts that currently match their conditions will show up as active. Resolved/old alerts won't be loaded back into the active state.
3. Clean up "stuck" alerts (zombie alerts)
If you have alerts that won't go away even after the underlying issue is fixed, you can delete the associated time-series data that's keeping the alert alive:
- Use the updated delete endpoint for TSDB series (note this deletes raw metric data, so use carefully):
curl -X POST http://your-prometheus-url/api/v1/admin/tsdb/delete_series \ -d 'match[]={__name__="your_metric_name"}' - After deleting the series, restart Prometheus to ensure the alert state is fully reset.
4. Suppress alert notifications (if using Alertmanager)
If you just want to stop getting notifications for old alerts (without removing them from Prometheus's state), use Alertmanager's silence feature. You can create a silence via the Alertmanager UI or API to mute specific alerts for a set duration.
内容的提问来源于stack exchange,提问作者Spangen




