首页 > 其他 > 详细

对binlog日志进行统计

时间:2017-03-02 13:58:17      阅读:200      评论:0      收藏:0      [点我收藏+]
# command format: python define_name.py file_name
import sys
import re
f = open(sys.argv[1])
update_list=[]
update_list2=[]
insert_list=[]
insert_list2=[]
delete_list=[]
delete_list2=[]
#line = f.readline()
#while len(line)!=0:
#print sys.argv[1,2,3,4,5,6,7,8,9]
for line in f:
    if not line.strip():
        continue
    line = re.sub(`,‘‘,line)
    v_par =re.match("(\s*)(\S+)(\s*)(.*)",line,re.I)
    if v_par.group(2).lower() != update and  v_par.group(2).lower() != delete and  v_par.group(2).lower() !=insert:
        #print line,
        continue
    elif v_par.group(2).lower()==update:
        c = re.match("(\w+)(\s+)(\w+\.)?(\w+)",line,re.I)
        update_list.append(c.group(4).lower())
    elif v_par.group(2).lower()==insert:
        c = re.match("(\w+)(\s*)(into)?(\s+)(\w+\.)?(\w+)(\s*\()?",line,re.I)
        insert_list.append(c.group(6).lower())
    elif v_par.group(2).lower()==delete:
        c = re.match("(\w+)(.*)(from)(\s+)(\w+\.)?(\w+)",line,re.I)
        delete_list.append(c.group(6).lower())

print TABLE_NAME,EXEC_COUNT,DML_TYPE
if len(update_list) > 0:
    update_list2=list(set(update_list))
    for ii in range(len(update_list2)):
        print update_list2[ii] ,update_list.count(update_list2[ii]),"update"


if len(insert_list) > 0:
    insert_list2=list(set(insert_list))
    for ii in range(len(insert_list2)):
        print insert_list2[ii] ,insert_list.count(insert_list2[ii]),"insert"


if len(delete_list) > 0:
    delete_list2=list(set(delete_list))
    for ii in range(len(delete_list2)):
        print delete_list2[ii] ,delete_list.count(delete_list2[ii]),"delete"

f.close();

运行脚本  python zhenban.py log001.log    ##前面是脚本的名字,后面是binlog的名字

得出的结果是

技术分享

需要自己用excel去进行分列和排序

对binlog日志进行统计

原文:http://www.cnblogs.com/tangbinghaochi/p/6490200.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!