kle 日志收集系统维护之清理索引及索引优化脚本
logstash每天往es建好索引,按天生成,就目前的需求,需要清理不需要的数据,以保证最新日志的速度展示,哈哈,瞎搞了这个脚本,路过的大神批评。
#!/usr/bin/env python
# coding:utf8
#author: shantuwqk@163.com
import sys,datetime
import os,time,commands
HOST = '192.168.35.125'
PORT = '9200'
#排除不需要删除的索引列表
NotDEL = ['g1_sms_collect']
def Del_Indices(last4):
TMP_LIST = []
DEL_DAY_LIST = []
file_info = '/tmp/es_indices_list.txt'
CURLCMD = 'curl http://%s:%s/_cat/indices?v > %s'%(HOST,PORT,file_info)
CURLINDEX_INFO = "cat /tmp/es_indices_list.txt | grep -v 'health status index'|egrep '*-%s'|awk '{print $3}'"%last4
#DEL_DAY_INFO = "%s|awk '{print $3}'"%CURLINDEX_INFO
s,v = commands.getstatusoutput(CURLCMD)
if s == 0:
with open(file_info,'r') as f:
st,vi = commands.getstatusoutput(CURLINDEX_INFO)
TMP_LIST.append(vi)
#DEL_DAY_LIST.append(vi)
else:
print "\033[31;1m curl cmd execute faild\033[0m"
# print DEL_DAY_LIST
for i in TMP_LIST[0].split('\n'):
DEL_DAY_LIST.append(i)
#sd,vd = commands.getstatusoutput('curl -XDELETE http://%s:%s/%s'%(HOST,PORT,i))
#print sd,vd,
print DEL_DAY_LIST
try:
for t in NotDEL:
DEL_DAY_LIST.remove("%s-%s"%(t,last4))
except Exception:
pass
for index in DEL_DAY_LIST:
sd,vd = commands.getstatusoutput('curl -XDELETE http://%s:%s/%s'%(HOST,PORT,index))
if __name__ == '__main__':
last4day = (datetime.date.today() - datetime.timedelta(days=3)).strftime('%Y.%m.%d')
#print last4day
Del_Indices(last4day)
最近由于es shard 老出问题, 在网上看有优化的功能,所以又扩展了以下脚本:做日常定时任务,主要保含清理和优化索引功能
#!/usr/bin/env python
# coding:utf8
#author:shantuwqk@163.com import sys,datetime
import os,time,commands
import sys,os HOST = 'localhost'
PORT = '9200'
#ES_ROOT = os.path.dirname(os.path.dirname(__file__))
ES_ROOT = '/'.join(os.getcwd().split('/')[:-1])
ES_BIN = ES_ROOT + '/bin'
ES_INDICES = ES_ROOT + '/data/elasticsearch/nodes/0/indices'
ES_OPTIMIZE = "_optimize"
ES_DEL_VAL = "_optimize?only_expunge_deletes=true"
print ES_ROOT
print ES_BIN
print ES_INDICES def Indiceslist(date):
indiceslist = []
s,v = commands.getstatusoutput("ls %s -l| awk '{print $9}'|egrep \"*-%s\""%(ES_INDICES,date))
#print "#########indices",s,v
if s == 0:
for i in v.split('\n'):
indiceslist.append(i)
return indiceslist
#print indiceslist def Del_Indices(date):
NotDEL = ['g1_sms_collect']
DEL_DAY_LIST = []
print date,
print Indiceslist(date)
for i in Indiceslist(date):
print i,
DEL_DAY_LIST.append(i)
try:
for t in NotDEL:
DEL_DAY_LIST.remove("%s-%s"%(t,date))
except Exception:
pass
print DEL_DAY_LIST
for index in DEL_DAY_LIST:
sd,vd = commands.getstatusoutput('curl -XDELETE http://%s:%s/%s'%(HOST,PORT,index))
if sd == 0:
print "DEL indices Sucess !!"
else:
print "DEL indices Failed !!"
ds,dv = commands.getstatusoutput('curl -XPOST http://%s:%s/%s/%s'%(HOST,PORT,index,ES_DEL_VAL))
if ds == 0:
print "Cel indices Sucess !!"
else:
print "Cel indices Failed !!" def es_optimize(date):
#print Indiceslist(date)
for i in Indiceslist(date):
print "curl -XPOST \"http://%s:%s/%s/%s\""%(HOST,PORT,i,ES_OPTIMIZE)
s,v = commands.getstatusoutput("curl -XPOST \"http://%s:%s/%s/%s\""%(HOST,PORT,i,ES_OPTIMIZE))
print s,v,
if s == 0:
print "\033[32;1mES Optimize Success !!!\033[0m"
else:
print "\033[31;1m Es Optimze Failed!!!\033[0m" def handle_cluster_status():
clustet_status = "curl -XGET \'http://localhost:9200/_cluster/health?pretty=true\'" def help_prompt():
print """
This program prints files to the standard output.
Options include:
--version : Prints the version number
--help : Helpful tips
--task : To operate on missions [delindices|optimze]
sample : python es_manage.py --task delindices
: python es_manage.py --task optimze
""" def error_prompt():
print '\033[31;1mUnknown option.Please refer to the help...\033[0m'
print "==============================================================="
help_prompt()
print "---------------------------------------------------------------"
sys.exit(1) if __name__ == '__main__': if len(sys.argv) == 1:
print "\033[31;1m No action specified.\033[0m"
help_prompt()
sys.exit(1)
if len(sys.argv) == 2 and sys.argv[1].startswith('--'):
if sys.argv[1][2:] == 'version':
print 'Version 1.0'
sys.exit(1)
elif sys.argv[1][2:] == 'help':
help_prompt()
if len(sys.argv) == 3 and sys.argv[1][2:] == 'task' and sys.argv[2] == "delindices":
DelDay = (datetime.date.today() - datetime.timedelta(days=3)).strftime('%Y.%m.%d')
Del_Indices(DelDay)
elif len(sys.argv) == 3 and sys.argv[1][2:] == 'task' and sys.argv[2] == "optimze":
yesterday = (datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y.%m.%d')
today = (datetime.date.today() - datetime.timedelta(days=0)).strftime('%Y.%m.%d')
print es_optimize(yesterday)
es_optimize(today)
else:
error_prompt()
exit(1)
kle 日志收集系统维护之清理索引及索引优化脚本的更多相关文章
- 用fabric部署维护kle日志收集系统
最近搞了一个logstash kafka elasticsearch kibana 整合部署的日志收集系统.部署参考lagstash + elasticsearch + kibana 3 + kafk ...
- Docker搭建EFK日志收集系统,并自定义es索引名
EFK架构图 一.EFK简介 EFK不是一个软件,而是一套解决方案,并且都是开源软件,之间互相配合使用,完美衔接,高效的满足了很多场合的应用,是目前主流的一种日志系统. EFK是三个开源软件的缩写,分 ...
- 基于Flume的美团日志收集系统 架构和设计 改进和优化
3种解决办法 https://tech.meituan.com/mt-log-system-arch.html 基于Flume的美团日志收集系统(一)架构和设计 - https://tech.meit ...
- Docker日志收集最佳实践
传统日志处理 说到日志,我们以前处理日志的方式如下: · 日志写到本机磁盘上 · 通常仅用于排查线上问题,很少用于数据分析 ·需要时登录到机器上,用grep.awk等工具分析 那么,这种方式有什么缺点 ...
- K8S学习笔记之k8s日志收集实战
0x00 简介 本文主要介绍在k8s中收集应用的日志方案,应用运行中日志,一般情况下都需要收集存储到一个集中的日志管理系统中,可以方便对日志进行分析统计,监控,甚至用于机器学习,智能分析应用系统问题, ...
- 用ELK搭建简单的日志收集分析系统【转】
缘起 在微服务开发过程中,一般都会利用多台服务器做分布式部署,如何能够把分散在各个服务器中的日志归集起来做分析处理,是一个微服务服务需要考虑的一个因素. 搭建一个日志系统 搭建一个日志系统需要考虑一下 ...
- 日志收集系统搭建-BELK
前言 日志是我们分析系统运行情况.问题定位.优化分析等主要数据源头.目前,主流的业务系统都采用了分布式.微服务的形式.如果想要查看日志,就需要从不同的节点上去查看,而且对于整个业务链路也非常不清晰.因 ...
- ELK+kafka构建日志收集系统
ELK+kafka构建日志收集系统 原文 http://lx.wxqrcode.com/index.php/post/101.html 背景: 最近线上上了ELK,但是只用了一台Redis在 ...
- [转载] 一共81个,开源大数据处理工具汇总(下),包括日志收集系统/集群管理/RPC等
原文: http://www.36dsj.com/archives/25042 接上一部分:一共81个,开源大数据处理工具汇总(上),第二部分主要收集整理的内容主要有日志收集系统.消息系统.分布式服务 ...
随机推荐
- 关于window.open弹出窗口被阻止的问题
原文:http://blog.csdn.net/fanfanjin/article/details/6858168 在web编程过程中,经常会遇到一些页面需要弹出窗口,但是在服务器端用window.o ...
- C关键字volatile总结
做嵌入式C开发的相信都使用过一个关键字volatile,特别是做底层开发的.假设一个GPIO的数据寄存器地址是0x50000004,我们一般会定义一个这样的宏: #define GDATA *((vo ...
- IntelliJ IDEA 创建 hello world Java web Maven项目从头到尾都有图有真相2017版本
学Java的大部分吧都是要整Java web开发项目的,那么最好用的编辑器估计就是这个 IntelliJ IDEA,然后现在maven管理项目是很流行的.然后我就示范一下,如何使用这个IntelliJ ...
- 数据输出保存生成word文档
ob_start(); //打开缓冲区 $header_str = '<html xmlns:o="urn:schemas-microsoft-com:office:office&qu ...
- set集合,深浅拷贝以及部分知识点补充
目录: 1.基础数据类型补充 2.set集合 3.深浅拷贝 一,基础数据类型补充 字符串的基本操作 li = ["李李嘉诚", "麻花藤", "⻩黄海 ...
- 实现全站 HTTPS ,为什么国内网站总是那么slow&&low呀!
1 https://konklone.com/post/switch-to-https-now-for-free# https://theintercept.com/2014/11/20/non-pr ...
- 弱网络模拟测试工具---易测app
易测功能介绍 易测是一款基于无线客户端研发场景的通用测试工具, 它通过在研发人员的自持机上提供各种辅助能力&标准化的专项测试服务来提升研发质量&效率. 易测app是阿里巴巴做的 ...
- hive 排序和聚集
1.order by 是对数据进行全排序,属于标准排序语句 order by 会对输入做全局排序,因此只有一个reducer(多个reducer无法保证全局有序)只有一个reducer,会导致当输入规 ...
- Mybatis笔记二:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
错误异常:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.test.dao.N ...
- BZOJ4408 [Fjoi 2016]神秘数 【主席树】
题目链接 BZOJ4408 题解 假如我们已经求出一个集合所能凑出连续数的最大区间\([1,max]\),那么此时答案为\(max + 1\) 那么我们此时加入一个数\(x\),假若\(x > ...