1. Place the check script on the monitored machine (Mysql Slave:
/Usr/local/zabbix/bin/check_mysql_repl.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 based on the actual situation
- Self. 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 ):
- Ifself. io = 'yes ':
- Return1
- Else:
- Return0
- Def get_ SQL _status (self ):
- Ifself. io = 'yes ':
- Return1
- Else:
- Return0
- 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 ()
2. Configure zabbix_agent.conf and add the Key and monitoring script:
Vi/usr/local/zabbix/etc/zabbix_agentd.conf. Add the following two lines at the end of the file:
UserParameter = mysql. repl_io,/usr/local/zabbix/bin/check_mysql_repl.py io UserParameter = mysql. repl_ SQL,/usr/local/zabbix/bin/check_mysql_repl.py SQL
UserParameter is fixed
Mysql. repl_io is the custom Key, which is used when the metric item is added below
/Usr/local/zabbix/bin/check_mysql_repl.py io is the above script and Parameter
Restart zabbix_agentd
3. Add metric items:
4. Add a trigger:
This trigger is used to trigger an alarm if the returned value of the script is not 1.
This is a simple master-slave monitoring configuration !~~