- zabbix自定义key监控mysql重要参数的运行情况
- 主要是通过mysql中"SHOW STATUS"命令获取当前数据库重要参数的运行情况,简单方便,监控mysql数据库必不可少,如需监控其他参数,依葫芦画瓢即可,。
- 1、在zabbix客户端的配置文件中打开或添加以下内容:
- UnsafeUserParameters=1
- UserParameter=mysql.Open_tables,/usr/local/zabbix/bin/mysql.py Open_tables
- UserParameter=mysql.Opened_tables,/usr/local/zabbix/bin/mysql.py Opened_tables
- UserParameter=mysql.Max_used_connections,/usr/local/zabbix/bin/mysql.py Max_used_connections
- UserParameter=mysql.Threads_connected,/usr/local/zabbix/bin/mysql.py Threads_connected
- UserParameter=mysql.Qcache_free_blocks,/usr/local/zabbix/bin/mysql.py Qcache_free_blocks
- UserParameter=mysql.Qcache_total_blocks,/usr/local/zabbix/bin/mysql.py Qcache_total_blocks
- UserParameter=mysql.Handler_read_first,/usr/local/zabbix/bin/mysql.py Handler_read_first
- UserParameter=mysql.Handler_read_key,/usr/local/zabbix/bin/mysql.py Handler_read_key
- UserParameter=mysql.Handler_read_rnd_next,/usr/local/zabbix/bin/mysql.py Handler_read_rnd_next
- UserParameter=mysql.Slow_queries,/usr/local/zabbix/bin/mysql.py Slow_queries
- 2./usr/local/zabbix/bin/mysql.py脚本的内容如下:
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #File:mysql_status.py
- import MySQLdb,sys
- user = 'monitor'
- passwd = '123456'
- a = sys.argv[1]
- try:
- conn = MySQLdb.connect(host = '127.0.0.1',user = user,passwd = passwd,connect_timeout = 2)
- cursor = conn.cursor()
- sql = "SHOW STATUS"
- cursor.execute(sql)
- alldata = cursor.fetchall()
- for data in alldata:
- if data[0] == a :
- #print data[0],data[1]
- print data[1]
- break
- cursor.close()
- conn.close()
- except Exception, e:
- print e
- sys.exit()
- '''''Open_tables
- Opened_tables
- Max_used_connections
- Threads_connected
- Qcache_free_blocks
- Qcache_total_blocks
- Handler_read_first
- Handler_read_key
- Handler_read_rnd_next
- Slow_queries'''
- 3.在zabbix服务器端设置相关的监控项即可,或者下载附件中的zabbix mysql监控模板xml文件,涵盖以上的监控项。
本文转自 lover00751CTO博客,原文链接:http://blog.51cto.com/wangwei007/1107620,如需转载请自行联系原作者