删除历史数据
默认情况下,管理时间序列的 API 是被禁用的,要启用它,我们需要在 Prometheus 的启动参数中添加--web.enable-admin-api这个参数如下[Service]中定义的
我的配置是在Prometheus的服务启动文件里添加
文件位置:vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System
[Service]
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:9090 --storage.tsdb.retention.time=5d --web.enable-admin-api
[Install]
WantedBy=multi-user.target
保存退出
从启动prometheus服务
systemctl restart prometheus.service
删除历史数据
#删除某个标签匹配的数据
curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]={instance=".*"}'
#删除某个指标数据
curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]={node_load1=".*"}'
#根据时间删除
curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]={node_load1=".*"}&start<2023-02-20T00:00:00Z&end=2023-02-25T00:00:00Z'
举例:删除10.10.201.86服务器2023年2月26日至2023年2月27日的所有数据
curl -X POST -g 'http://10.10.201.86:9090/api/v1/admin/tsdb/delete_series?match[]={node_load1=".*"}&start<2023-02-26T00:00:00Z&end=2023-02-27T00:00:00Z'
从启动prometheus服务
systemctl restart prometheus.service
从启动服务以后 需要稍等一下 等服务器都加载完成
http://10.10.201.86:9090/targets