1, Zabbix add MySQL monitoring template (temple-app-mysql), you also need to add a key to the client to fetch the value.
2. Write scripts to get the various status values of MySQL. A directory can be pinned, specifically for monitoring scripts. Like/usr/local/zabbix/scripts/chk_mysql.sh.
#!/bin/bash
# -------------------------------------------------------------------------------# filename: chk_mysql.sh# Revision: 1.0# Date: 2015/09/07# Author: Winngins Yu# email: [email protected]# website: www.drinkboy.com# Description: # Notes: ~# -------------------------------------------------------------------------------# copyright: 2015 (c) Winngins Yu# License: GPL # user name MySQL _user= ' root ' # password mysql_pwd= ' liujinWANG1985 ' # host address/ipmysql_host= ' 127.0.0.1 ' # Port mysql_port= ' 3306 ' # data connection mysql_conn= "/alidata/mysql/bin/mysqladmin -u ${mysql_user} -p${mysql_pwd} -H${mysql_host} -p${mysql_port} " # parameter is correct if [ $# -ne " 1 " ];then echo "arg error!" fi # get data Case $1 in uptime) result= ' ${mysql_conn} status|cut -f2 -d ":" |cut -f1 -d "T" echo $result ;; com_update) result= ' ${MYSQL _conn} extended-status |grep -w "Com_update" |cut -d "|" -f3 ' echo $result ;; slow_queries) result= ' ${ Mysql_conn} status |cut -f5 -d ":" |cut -f1 -d "O" echo $result ;; com_select) result= ' ${MYSQL _conn} extended-status |grep -w "Com_select" |cut -d "|" -f3 ' echo $result ;; com_rollback) result= ' ${ mysql_conn} extended-status |grep -w "Com_rollback" |cut -d "|" -f3 ' echo $result ;; questions) result= ' ${mysql_conn} status|cut -f4 -d ":" |cut - f1 -d "S" ' echo $result ;; com_insert) result= ' ${MYSQL _conn} extended-status |grep -w "Com_insert" |cut -d "|" -f3 ' echo $result ;; com_delete) result= ' ${MYSQL _conn} extended-status |grep -w "Com_delete" |cut -d "|" -f3 '      &Nbsp; echo $result ;; com_commit) result= ' ${MYSQL _conn} extended-status |grep -w "Com_commit" |cut -d "|" -f3 ' echo $result ;; bytes_sent) result= ' ${MYSQL _conn} extended-status |grep -w "bytes_sent" |cut -d "|" -f3 ' echo $result           &NBsp; ;; bytes_received) result= ' ${ mysql_conn} extended-status |grep -w "bytes_received" |cut -d "|" -f3 ' echo $result ;; com_begin) result= ' ${MYSQL_ conn} extended-status |grep -w "Com_begin" |cut -d "|" -f3 ' echo $result ;; *) echo "Usage:$0 (uptime| com_update| slow_queries| Com_select| com_rollback| questions| Com_insert| com_delete| Com_commit| Bytes_sent| bytes_received| Com_begin) " ;; esac
3, modify Zabbix configuration file/usr/local/zabbix-agentd/etc/zabbix_agentd.conf, add
#获取mysql版本UserParameter =mysql.version,mysql-v# #获取mysql性能指标, this is the script defined above Userparameter=mysql.status[*],bash/ alidata/zabbix-agentd/scripts/chk_mysql.sh $1# #获取mysql运行状态UserParameter =mysql.ping,/alidata/mysql/bin/ mysqladmin-uroot-pliujinwang1985-p3306-h127.0.0.1 Ping | Grep-c aliveuserparameter=mysql.process,/alidata/mysql/bin/mysql-uroot-pliujinwang1985-p3306-h127.0.0.1-e "Show Processlist "2>/dev/null|wc-l
4. Restart the Zabbix client
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/C7/wKiom1XtHzSDiIEYAAUTGQ2CEss026.jpg "style=" float: none; "title=" qq20150907132106.jpg "alt=" Wkiom1xthzsdiieyaautgq2cess026.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/C3/wKioL1XtIV7j8TGRAATxWYO1_gE148.jpg "style=" float: none; "title=" qq20150907132124.jpg "alt=" Wkiol1xtiv7j8tgraatxwyo1_ge148.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/C7/wKiom1XtHzbSekO5AASFnTpxDWg351.jpg "style=" float: none; "title=" qq20150907132139.jpg "alt=" Wkiom1xthzbseko5aasfntpxdwg351.jpg "/>
This article is from the "Ops Space" blog, so be sure to keep this source http://drinkboy.blog.51cto.com/10606290/1692247
Zabbix monitoring MySQL