通过Prometheus的API接口可实现删除Job数据
Prometheus官方API
官网文档
:https://prometheus.io/docs/prometheus/latest/querying/api/
删除Job
1、启动Prometheus的时添加参数–web.enable-admin-api
nohup ./prometheus --config.file=prometheus.yml --web.enable-admin-api &
2、删除某个时间范围内所选的数据。实际数据仍存在于磁盘上。
参数:
match[]=<series_selector>
:重复的标签匹配器参数,用于选择要删除的系列。必须至少提供一个参数。
start=<rfc3339 | unix_timestamp>
:开始时间戳。可选,默认为尽可能短的时间。
end=<rfc3339 | unix_timestamp>
:结束时间戳。可选,默认为最大可能时间。
不同时提及开始时间和结束时间将清除数据库中匹配系列的所有数据。
例:
$ curl -X POST \
-g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]=up&match[]=process_start_time_seconds{job="prometheus"}'
3、从磁盘中删除数据并清理现有的逻辑删除。这可以在删除用以释放空间。
这不需要任何参数或主体。
$ curl -XPOST http://localhost:9090/api/v1/admin/tsdb/clean_tombstones
实测结果: