python监控mysql日志,python 监控mysql-Threads

监控mysql-Threads值,当值大于设定阀值50时。将 show full processlist 输出到日志。

mysql-th.pyimport 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 

else:

print "not  ok "

while.pyimport 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值