UsepythonWrite a monitoringMySQLthe script, inZabbix WebAdd the Template:
## First Use MySQLdb interface associated with the database.
[[Email protected] python]# cat check_mysql_custom.py#!/usr/local/bin/python '] Author = chenmingle "" Description:get mysql status "import osimport systry: import MySQLdb as mysqlexcept Exception, e: print e print "Pip install mysql-python" Sys.exit (1) con = mysql.connect (host= ' localhost ', user= ' root ', passwd= ' passwd ',) def processlist (): Cur = con.cursor () sql1 = ' show processlist ' A = str (Cur.execute (SQL1)) print adef slave_status (): cur = con.cursor () sql2 = cur.execute (' show status like "%slave_running%"; ') status2 = str (Cur.fetchall ()) &nBsp; check2 = status2.split ("'") [3] if check2 == ' on ': print 0 else: print 1def show_status (type): Cur = con.cursor () b = cur.execute (' show status like "%s"; ') % (type)) For i in cur.fetchall (): Cat = str (i) Check = str (Cat.split ("'") ) [3]) Print checkdef main (type): if type == ' processlist ':p rocesslist () elif type == ' slave_status ': Slave_status () else:show_ Status (Type) if __name__ == ' __main__ ': try: type = sys.argv[1] except exception, e: print "Usage: python %s type" % sys.argv[0] sys.exit (1) main (type)
## test the script:
[[email protected] python]# python check_mysql_custom.py processlist3[[email protected] python]# python check_mysql_ custom.py Connections55876
## The test shows all the MySQL in Show Status can output information:
## Write a template configuration file (custom Key value):
[email protected] zabbix_agentd.d]# cat Mysql_custom.confuserparameter=mysql. custom[*],/usr/local/bin/python/home/python/check_mysql_custom.py $
## in the Zabbix Web add a template to the interface:
## Add a appaliactions:
## Join Item values:
Use Python to write a script to monitor MySQL and add a template to the Zabbix Web