只保留三天
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import os
import datetime
# 时间转化为字符串
now_time = datetime.datetime.now().strptime(datetime.datetime.now().strftime("%Y.%m.%d"),"%Y.%m.%d")
os.system("curl -XGET http://127.0.0.1:9200/_cat/indices > date.txt")
with open("date.txt","r") as f:
for line in f.readlines():
index = line.strip().split()[2]
try:
index_strftime = datetime.datetime.strptime(index.split("-")[-1], "%Y.%m.%d")
Ca = (now_time - index_strftime)
if str(Ca).split()[0] == "0:00:00":
continue
elif int(str(Ca).split()[0]) >= 3:
command = "curl -XDELETE http://127.0.0.1:9200/%s" % index
print(command)
os.system(command)
else:
print(index,"no del")
except:
pass
添加定时任务
[root@us-prod-sre-eslog-node-2 centos]# crontab -e 00 03 * * * /bin/python /home/centos/delete-es.py
此处为隐藏的内容
注册登录后,方可查看
登录
继续阅读


![EFK集群[案例]](https://devops.ubuntu.ltd/wp-content/uploads/2022/09/2022092017505680.png?x-oss-process=image/resize,m_fill,w_280 ,h_210, limit_0)










评论