In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use python to send MySQL slow log email, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
One demand
Because the development aims at the stability construction of a certain system, it needs to audit the slow log of the database system and check and optimize it. Communicate with the developer to choose the way to send slow queries to the developed mailbox on a regular basis, summarize them daily, and then evaluate and optimize slow query together.
Implementation of two tools
Mail.py script
#! / usr/bin/env python
#-*-coding: utf-8-*-
# mail.py
Import os.path
Import time
Import sys
Import os
Import json
Import string
Import random
Import smtplib
Import time
From datetime import date
From email.mime.multipart import MIMEMultipart
From email.mime.text import MIMEText
From email.mime.image import MIMEImage
From email.Header import Header
From email.MIMEText import MIMEText
From email.MIMEMultipart import MIMEMultipart
Mail_user= "xxx@xxxx.com"
Mail_pass= "xxxxx"
Mail_smtp_server= "smtp.xxxxx.com"
Mail_smtp_port= 25
Def sendMail (contents,subject,attach,mail_to):
LTime=str (time.strftime ('% Y% m% dudes% Happy journal time.localtime (time.time ()
Msg = MIMEMultipart ('related')
If subject== "":
Subject='test'
Msg ['Subject'] = subject+ "Time:" + lTime
Msg ['From'] = mail_user
Msg ['To'] = ";" .join (mail_to)
Html= ""
For cont in contents:
Html = html+cont [0]
MsgHtml = MIMEMultipart ('alternative')
MsgHtml.set_charset ('UTF-8')
MsgAtt = MIMEText (open (attach,'rb'). Read (), 'base','gbk')
MsgAtt ["Content-Type"] = 'application/octet-stream'
MsgAtt ["Content-Disposition"] = 'attachment; filename= "' + subject+'"'
Msg.attach (msgAtt)
Try:
Smtp = smtplib.SMTP ()
Smtp.connect (mail_smtp_server,mail_smtp_port)
Smtp.login (mail_user,mail_pass)
Smtp.sendmail (mail_user,mail_to,msg.as_string ())
Smtp.close ()
Except Exception,e:
Print str (e)
SendSlowlog.py
#! / usr/bin/env python
#-*-coding: utf-8-*-
Import mail # # uses the above script
Import sys
Import time
Import os
Import datetime
From datetime import date
From os.path import join, getsize
Def sendSlowlog (subject_info,attach,mail_to):
Size = os.path.getsize (attach)
If (size > 1):
Mail.sendMail ("", subject_info,attach,mail_to)
If _ _ name__ = ='_ _ main__':
Mail_to= ["qilong.yangql@xxxx.com"]
LDate=str (time.strftime ('% Y% m% dhamma time.localtime (time.time ()
LTime=str (time.strftime ('% Y% m% dudes% Happy journal time.localtime (time.time ()
Subject_info= "Slowlog of DBname" + lTime
Attach= "/ u01qmy3306 attach= _" + lDate + "/ lTime."
SendSlowlog (subject_info,attach,mail_to)
Note
This system has divided slow log every hour, about how to cut, you can think about it.
On how to use python to send MySQL slow log mail to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.