zabbix自定义key监控mysql重要参数的运行情况

 

 
 
  1. zabbix自定义key监控mysql重要参数的运行情况  
  2.  
  3. 主要是通过mysql中"SHOW STATUS"命令获取当前数据库重要参数的运行情况,简单方便,监控mysql数据库必不可少,如需监控其他参数,依葫芦画瓢即可,。  
  4.  
  5. 1、在zabbix客户端的配置文件中打开或添加以下内容:  
  6. UnsafeUserParameters=1 
  7. UserParameter=mysql.Open_tables,/usr/local/zabbix/bin/mysql.py Open_tables  
  8. UserParameter=mysql.Opened_tables,/usr/local/zabbix/bin/mysql.py Opened_tables  
  9. UserParameter=mysql.Max_used_connections,/usr/local/zabbix/bin/mysql.py Max_used_connections  
  10. UserParameter=mysql.Threads_connected,/usr/local/zabbix/bin/mysql.py Threads_connected  
  11. UserParameter=mysql.Qcache_free_blocks,/usr/local/zabbix/bin/mysql.py Qcache_free_blocks  
  12. UserParameter=mysql.Qcache_total_blocks,/usr/local/zabbix/bin/mysql.py Qcache_total_blocks  
  13. UserParameter=mysql.Handler_read_first,/usr/local/zabbix/bin/mysql.py Handler_read_first  
  14. UserParameter=mysql.Handler_read_key,/usr/local/zabbix/bin/mysql.py Handler_read_key  
  15. UserParameter=mysql.Handler_read_rnd_next,/usr/local/zabbix/bin/mysql.py Handler_read_rnd_next  
  16. UserParameter=mysql.Slow_queries,/usr/local/zabbix/bin/mysql.py Slow_queries  
  17.  
  18. 2./usr/local/zabbix/bin/mysql.py脚本的内容如下:  
  19.  
  20. #!/usr/bin/env python  
  21. # -*- coding: utf-8 -*-  
  22. #File:mysql_status.py  
  23. import MySQLdb,sys  
  24. user = 'monitor' 
  25. passwd = '123456' 
  26. a = sys.argv[1]  
  27. try:  
  28.     conn = MySQLdb.connect(host = '127.0.0.1',user = user,passwd = passwd,connect_timeout = 2)  
  29.     cursor = conn.cursor()  
  30.     sql = "SHOW STATUS" 
  31.     cursor.execute(sql)  
  32.     alldata = cursor.fetchall()  
  33.     for data in alldata:  
  34.         if data[0] == a :  
  35.             #print data[0],data[1]  
  36.             print data[1]  
  37.             break 
  38.     cursor.close()  
  39.     conn.close()  
  40. except Exception, e:    
  41.     print e    
  42.     sys.exit()  
  43.  
  44. '''''Open_tables  
  45. Opened_tables  
  46. Max_used_connections  
  47. Threads_connected  
  48. Qcache_free_blocks  
  49. Qcache_total_blocks  
  50. Handler_read_first  
  51. Handler_read_key  
  52. Handler_read_rnd_next  
  53. Slow_queries''' 
  54.  
  55. 3.在zabbix服务器端设置相关的监控项即可,或者下载附件中的zabbix mysql监控模板xml文件,涵盖以上的监控项。 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值