mysql执行sql及慢查询监控
# -*- coding: utf-8 -*-__author__ = 'river'
import MySQLdb as mysql
import re
from datetime import datetime, timedelta
import smtplib
from email.mime.text import MIMEText
def sendHtmlMail(mailcontent,myip):
try:
yestoday=(datetime.now()-timedelta(days=1)).strftime("%Y-%m-%d")
sender = 'xxx@xxx.com'
receiver = ['xxx@xxx.com']
subject = myip+' mysql operation report '+yestoday
smtpserver = 'smtp.exmail.xx.com'
username = 'xxx@xxx.com'
password = 'xxxxx'
msg = MIMEText(mailcontent,'html','utf-8')#'你好','text','utf-8'
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = 'xxx@xxxxxxxx.com'
smtp = smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
except Exception, e:
print e,'send mail error'
if __name__=='__main__':
result=None
htmlfile='mysqlLogMon.html'
myiplist=['192.168.10.10','192.168.10.19']
yestoday=(datetime.now()-timedelta(days=1)).strftime("%Y-%m-%d 00:00:00")
today=datetime.now().strftime("%Y-%m-%d 00:00:00")
for myip in myiplist:
sql="select user_host,argument from general_log_dba where event_time >='%s' and event_time
页:
[1]