MySQL slow query log cutting, log analysis

Source: Internet
Author: User
Tags mysql slow query log

#!/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)


This article is from the "Original Python publishing area" blog, so be sure to keep this source http://cuihailong.blog.51cto.com/2923450/1409565

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.