mysql慢查询日志切割,日志分析

时间:2014-05-13 02:39:47   收藏:0   阅读:482

#!/usr/bin/env python

#coding:utf8

import os,sys

import datetime,shutil,subprocess

from config.config import slow_config

class cut_mysql(object):

   mysql_user,mysql_pass,date_day,slow_log_name,slow_log_path,mysqlsla_log_name,mysqldumpslow_log_name,new_log_path,new_log_name,cut_command,mysqlsla_cmd,mysqldumpslow_cmd = slow_config

   def __init__ (self):

       self.mysql_slow()

   def mysql_slow (self):

       os.chdir(self.slow_log_path)

       if self.new_log_path in os.listdir(self.slow_log_path):

           pass

       else:

           os.mkdir(self.slow_log_path+self.new_log_path)

       if self.slow_log_name in os.listdir(self.slow_log_path):

           os.rename(self.slow_log_name,self.new_log_name)

           if self.new_log_name in os.listdir(self.slow_log_path+self.new_log_path):

               pass

           else:

               shutil.move(self.new_log_name,self.slow_log_path+self.new_log_path)

       reload_slow=subprocess.Popen(self.cut_command,shell=True)

       self.mysql_slow_show()

   def mysql_slow_show(self):

       cmd_list=[self.mysqlsla_cmd,self.mysqldumpslow_cmd]

       for i in cmd_list:

               seiri_log=subprocess.Popen(i,shell=True)


本文出自 “原创python发布区” 博客,请务必保留此出处http://cuihailong.blog.51cto.com/2923450/1409565

mysql慢查询日志切割,日志分析,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!