接口测试的核心概念是什么
296
2022-08-29
读取 Mysql Binlog 日志文本(读取应用列表是指什么)
作为DBA应该清楚到底哪张表的DML操作频繁,用刚学的Python写了一个脚本:
#!/bin/env python# -*- encoding: utf-8 -*-#-------------------------------------------------------------------------------# Name: readbinlog.py# Purpose: 读MySQL Binlog文本# Author: zhoujy# Created: 2012-09-28# update: 2012-09-28# Copyright: (c) zhoujy 2012# Licence: zhoujy#-------------------------------------------------------------------------------import sysInsert = []Insdict = {}Update = []Upddict = {}Delete = []Deldict = {}def read_file(file): f = open(file) while True: line = f.readline() if line.lower().find('insert') > -1: line_list = line.lower().split() for idx,name in enumerate(line_list): if name == 'into' and line_list[0]=='insert': Insert.append(line_list[idx+1].split('(')[0]) if line.lower().find('update') > -1: line_list = line.lower().split() for idx,name in enumerate(line_list): if name == 'set' and line_list[0]=='update': Update.append(line_list[idx-1]) if line.lower().find('delete') > -1: line_list = line.lower().split() for idx,name in enumerate(line_list): if name == 'from' and line_list[0]=='delete': Delete.append(line_list[idx+1]) if line == '': break f.close() print ('INSERT').center(60,'*') for n in Insert: Insdict[n] = Insdict.get(n,0)+1 List = sorted(Insdict.items(),key=lambda i: -i[1]) Sort = 0 for kv in List: if Sort < 10: print kv[0].rjust(30) + ' : ' + str(kv[1]) Sort += 1 print ('UPDATE').center(60,'*') for n in Update: Upddict[n] = Upddict.get(n,0)+1 List = sorted(Upddict.items(),key=lambda i: -i[1]) Sort = 0 for kv in List: if Sort < 10: print kv[0].rjust(30) + ' : ' + str(kv[1]) Sort += 1 print ('DELETE').center(60,'*') for n in Delete: Deldict[n] = Deldict.get(n,0)+1 List = sorted(Deldict.items(),key=lambda i: -i[1]) Sort = 0 for kv in List: if Sort < 10: print kv[0].rjust(30) + ' : ' + str(kv[1]) Sort += 1if __name__ == '__main__': Insert = read_file(sys.argv[1])
效果:python read_binlog.py binlog1.txt
***************************INSERT*************************** snase : 77807 snpost : 62554 justhits : 13842 snoblog : 9115 ucaction : 1700 jutload : 1281 snsaper : 1103 jutcord : 663 sfeeds : 654 snT : 594***************************UPDATE*************************** juted : 10919 js : 9663 jpost : 8704 jer : 6883 jd : 6222 sse : 1270 jft : 565 jut : 561 jd : 521 jc : 504***************************DELETE*************************** sne : 182 snsg : 149 snew : 74 juine : 66 sage : 48 snst : 41 sopic : 22 jutward : 21 jurite : 18 juage : 17
~~~~~~~~~~~~~~~ 万物之中,希望至美 ~~~~~~~~~~~~~~~
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~