python监控mysql数据改变_python个人记录3 mysql监控

该博客使用Python连接并监控MySQL数据库,检查Threads_running状态、max_user_connections限制,当达到预设阈值时触发报警。同时监控从库的Slave_IO_Running和Slave_SQL_Running,以及Seconds_Behind_Master延迟,确保数据同步正常。
摘要由CSDN通过智能技术生成

#!/usr/bin/python

import MySQLdb

import pycurl

def master_work(ip,port):

print ip,port

conn=MySQLdb.connect(host=str(ip),user='***',passwd='****',port=int(port))

cur=conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)

cur.execute('show status;')

result=cur.fetchall()

#conn1=result[-5]['Value']

for result_master in result:

if result_master['Variable_name'] == 'Threads_running':

conn1=result_master['Value']

print str(ip),str(port),str(conn1)

cur.execute('show global variables like "%conn%";')

result_2=cur.fetchall()

for results_master in result_2:

if results_master['Variable_name'] == 'max_user_connections':

max_conn=results_master['Value

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值