Zabbix monitors the master-slave synchronization (replication) Status of mysqlMasterSlave, with a script attached

Source: Internet
Author: User
When Zabbix is used to monitor the server, the master-slave status of Mysql is used. For Mysql master-slave configuration, see this article: [memo] mysqlMasterSlave master-slave synchronization (replication) configuration and FAQs. We know that after Mysql master-slave replication synchronization (replication) is started, it is successful only when the following two conditions are met: Slave_IO_Running:

When Zabbix is used to monitor the server, the Master-Slave status of Mysql is used. For Mysql Master-Slave configuration, see this article: [memo] mysql Master Slave Master-Slave synchronization (replication) configuration and FAQs. We know that after Mysql master-slave replication synchronization (replication) is started, it is successful only when the following two conditions are met: Slave_IO_Running:

When Zabbix is used to monitor the server, the Master-Slave status of Mysql is used. For Mysql Master-Slave configuration, see this article: [memo] mysql Master Slave Master-Slave synchronization (replication) configuration and FAQs.

We know that after Mysql master-slave replication synchronization (replication) is started, it is successful only when the following two conditions are met:

Slave_IO_Running: YesSlave_SQL_Running: Yes
Script 1

Create a script file, mysqlms. sh

#!/bin/bash/usr/local/mysql/bin/mysql -uzabbix -e 'show slave status\G' |grep -E "Slave_IO_Running|Slave_SQL_Running"|awk '{print $2}'|grep -c Yes

Place it in a directory (with permission required). Put it in/etc/zabbix/mysqlms. sh and add the following statement below zabbix_agentd.conf:

UserParameter=mysql.slavestatus,/etc/zabbix/mysqlms.sh

Restart zabbix-agent:

sudo service zabbix-agent restart

Run the following statement on the Server where Zabbix-Server is located to test whether the statement is successful:

zabbix_get -s 192.168.1.106 -k  mysql.slavestatus

192.168.1.106 indicates the server where the script is located, and mysql. slavestatus indicates the Key value. If 2 is returned, the master-slave service is normal.
Add the monitoring item to items for test on the web platform, and set the alarm notification.
(For details about how to add ietms, see add and configure custom monitoring metrics for Zabbix server monitoring system deployment (2 ))

Script 2

Create script mysqlms2.py

#! /Usr/bin/python # coding: UTF-8 import MySQLdb import sys class check_mysql_repl (): def _ init _ (self): self. dbhost = 'localhost' self. dbuser = 'root' self. dbpass = 'wisp888' self. dbport = 3306 self. sock = "/data/db_misc/mysql_3306.sock" self. conn = MySQLdb. connect (unix_socket = self. sock) # connect to self according to the actual situation. cursor = self. conn. cursor (cursorclass = MySQLdb. cursors. dictCursor) self. SQL = 'show slave status' Self.cursor.exe cute (self. SQL) self. data = self. cursor. fetchall () self. io = self. data [0] ['slave _ IO_Running '] self. SQL = self. data [0] ['slave _ SQL _Running '] self. conn. close () def get_io_status (self): if self. io = 'yes': return 1 else: return 0 def get_ SQL _status (self): if self. io = 'yes': return 1 else: return 0 if _ name _ = "_ main _": if len (sys. argv )! = 2: print "Usage: % s [io | SQL]" % sys. argv [0] sys. exit (1) mysql = check_mysql_repl () if sys. argv [1] = "io": print mysql. get_io_status () elif sys. argv [1] = "SQL": print mysql. get_ SQL _status ()

(The script is from the network)
Open the editing File

vi /etc/zabbix/zabbix_agentd.conf

Add the following content below:

UserParameter=mysql.repl_io,/etc/zabbix/mysqlms2.py io UserParameter=mysql.repl_sql,/etc/zabbix/mysqlms2.py sql

Other settings are the same as Script 1.

.

Original article address: Zabbix monitors the Master-Slave synchronization (replication) Status of the mysql Master server Load balancer instance, attaches a script, and thanks to the original author for sharing.

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.