日常管理03-监控MYSQL主从延时3秒脚本;
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了日常管理03-监控MYSQL主从延时3秒脚本;相关的知识,希望对你有一定的参考价值。
#!/bin/env python # -*- encoding: utf-8 -*- import time import os import sys import json import re import thread mysql_stat_list = [] class MySQLMonitorInfo(): def __init__(self): pass def is_slave(self): m = "mysql -e 'SHOW Slave statusG' " data = os.popen(m).readlines() if data == []: return '',False else: return data,True def stat_info(self): data,isslave = self.is_slave() if is slave: Str_string = {} for d in data[1:]: ds = d.replace(" ","").replace(" ","").split(":") Str_string[ds[0].strip()] = ds[1].strip() #print Str_string result = { 'name': '%s' % ('slave.iorun'), 'groups': "MysqlDelay3", 'value': 1 if Str_string['Slave_IO_Running'] == 'Yes' else 2, 'status': 1 if Str_string['Slave_IO_Running'] == 'Yes' else 2, 'command': sys.argv[0], 'messages': "%s %s"%('Slave_IO_Running', '正常' if Str_string['Slave_IO_Running'] == 'Yes' else "停止"), } mysql_stat_list.append(result) result = { 'name': '%s' % ('slave.delay3'), 'groups': "MysqlDelay3", 'value': Str_string['Seconds_Behind_Master'], 'status': 1 if int(Str_string['Seconds_Behind_Master']) < int(sys.argv[1]) else 2, 'command': sys.argv[0], 'messages': "%s %s"%('Seconds_Behind_Master', Str_string['Seconds_Behind_Master']), } mysql_stat_list.append(result) result = { 'name': '%s' % ('slave.sqlrun'), 'groups': "MysqlNew", 'value': 1 if Str_string['Slave_SQL_Running'] == 'Yes' else 2, 'status': 1 if Str_string['Slave_SQL_Running'] == 'Yes' else 2, 'command': sys.argv[0], 'messages': "%s %s"%('Slave_SQL_Running', "正常" if Str_string['Slave_SQL_Running'] == 'Yes' else "停止"), } return mysql_stat_list.append(result) else: return {} def get_data(host,tid): return MySQLMonitorInfo().stat_info() if len(sys.argv) > 4: for host in sys.argv[1].split(","): thread.start_new_thread(get_data, (host, 1)) else: get_data("", "") print json.dumps(mysql_stat_list)
以上是关于日常管理03-监控MYSQL主从延时3秒脚本;的主要内容,如果未能解决你的问题,请参考以下文章