Daily management 03-monitor MySQL master-slave delay 3-second script;

Source: Internet
Author: User

Tag:json   turn    monitoring    print   result    ace   dump   .sql   master   

#!/bin/env python# -*- encoding: utf-8 -*-import timeimport osimport  Sysimport jsonimport reimport threadmysql_stat_list = []class mysqlmonitorinfo () :       def __init__ (self):             pass      def is_slave (self):             m =  "mysql -e  ' show slave  Status\g '               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 ("\ T", ""). Split (":")                 str_string[ds[ 0].strip ()] = ds[1].strip ()                   #print &NBsp 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],                &nbsP; ' Messages ':  "%s %s"% (' slave_io_running ',  ' normal '  if str_string[' slave_io_running '] = =  ' Yes '  else  ' Stop '),                 }                 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 ',  "normal"  if str_string[' slave_sql_running '] ==  ' Yes '  else  ' Stop '),                 }                 Return mysQl_stat_list.append (Result)                  else:                       return {}         Def get_data (Host,tid):             return  mysqlmonitorinfo (). Stat_info ()        if len (SYS.ARGV)  > &NBSP;4:&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;FOR&NBSP;HOST&NBSP;IN&NBSP;SYS.ARGV[1]. Split (","):               thread.start_ New_thread (get_data,  (host, 1))           else:               get_data (", " ")       &Nbsp;       print json.dumps (Mysql_stat_list)


Daily management 03-monitor MySQL master-slave delay 3-second script;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.