python 监控mysql-Threads
python 监控mysql-Threads
监控mysql-Threads值,当值大于设定阀值50时。将 show full processlist 输出到日志。 mysql-th.py
import commands
import time
import datetime
now = datetime.datetime.now()
t= now.strftime("%Y-%m-%d-%H-%M-%S")
file_th = open('thfile.txt', 'a+')
th = commands.getstatusoutput("mysql -ubbs -h mysql主机ip -p密码 -e 'status'|grep Threads|awk '{print $2}'")
th_int= int(th[1])
if th[0] ==0:
print "ok"
file_th.write(th[1] +' '+t +'\n')
file_th.close( )
if th_int >50:
print "thread > 50"
file_proc =open('log/%s.log' % t ,'w+')
file_proc.write(commands.getstatusoutput("mysql -ubbs -h mysql主机ip -p密码 -e 'show full processlist'
")[1]+'\n' )
file_proc.close()
else:
print "thread < 50"
else:
print "not ok "
while.py
import os
import time
while True:
os.system("python mysql-th.py")
time.sleep(30)
日志输出到
thfile.txt
例:
24 2015-10-15-23-25-39
12 2015-10-15-23-25-41
11 2015-10-19-10-14-39
21 2015-10-19-10-14-41
第一列是线程数 第二列是时间
如果第一列大于设定阀值50 则生成以时间命名的日志文件,记录“show full processlist” 内容
例:
2015-10-15-23-25-41.log
相关内容
- 暂无相关文章
评论关闭