如何从Prometheus v2中删除时间序列,特别是一系列警报

Spa*_*gen 5 prometheus

我们正逐渐着手处理警报,因此不时需要清除旧警报(通过调用HTTP API来完成),以删除存储警报的伪时间序列,例如:

DELETE https://prometheus/api/v1/series?match[]={__name__="ALERTS"}
Run Code Online (Sandbox Code Playgroud)

我们最近将Prometheus服务器从1.8升级到2.2.1。

现在调用此端点可以得到

{
    "status": "error",
    "errorType": "internal",
    "error": "not implemented"
}
Run Code Online (Sandbox Code Playgroud)

我进行了一些研究,发现了各个位置的解决方案,下面将在总结中总结该解决方案,以防它对我的StackOverflowers有用。

Spa*_*gen 9

首先,Prometheus 2默认情况下未启用admin API。必须通过使用以下选项启动服务器,才能使其处于活动状态

--web.enable-admin-api
Run Code Online (Sandbox Code Playgroud)

v2中有一个新端点

https://prometheus/api/v2/admin/tsdb/delete_series
Run Code Online (Sandbox Code Playgroud)

这需要POST指定搜索条件,例如,对于名称ALERTS为警报名称的时间序列,从所选工具MyTestAlert中将以下内容发布application/jsondelete_series端点(在Mac上用Postman 6测试)

{
    "matchers": [{
        "type": "EQ",
        "name": "__name__",
        "value": "ALERTS"
    },
    {
        "type": "EQ",
        "name": "alertname",
        "value": "MyTestAlert"
    }]
} 
Run Code Online (Sandbox Code Playgroud)

为了保持完整性并释放警报持续存在的磁盘空间,请POST

https://prometheus/api/v2/admin/tsdb/clean_tombstones
Run Code Online (Sandbox Code Playgroud)

答案汇总自:

  • 使用 `/api/v1/admin/tsdb/delete_series` 和 `/api/v1/admin/tsdb/clean_tombstones` (v1 而不是提及 v2)。请参阅https://prometheus.io/docs/prometheus/latest/querying/api/#delete-series (2认同)