---恢复内容开始---
在/usr/local/zabbix/etc/zabbix_agentd.conf增加
# 获取mysql性能指标UserParameter=mysql.status[*],/usr/local/zabbix/bin/check_mysql.sh $1
/usr/local/zabbix/bin/check_mysql.sh脚本内容为
#!/bin/bash# -------------------------------------------------------------------------------# FileName: check_mysql.shMYSQL_CONN="/usr/bin/mysqladmin"# 参数是否正确if [ $# -ne "1" ];then echo "arg error!"fi# 获取数据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` 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 ;; 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 ;; Slave)# result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3`# echo $result array=(`/usr/bin/mysql -e "show slave status\G"|grep "Running" |awk '{print $2}'`) if [ "${array[0]}" == "Yes" ] && [ "${array[1]}" == "Yes" ] then echo 0 else echo 1 fi ;; *) 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|Slave)" ;;esac
zabbix模版内容:
3.4 2018-06-07T06:25:56Z Templates Template App MySQL Template App MySQL Templates MySQL MySQL status 0 mysql.ping 1m 1w 365d 0 3 0 0 0 0 It requires user parameter mysql.ping, which is defined in userparameter_mysql.conf. 0 - MySQL server is down 1 - MySQL server is up 0 MySQL Service state MySQL bytes received per second 0 mysql.status[Bytes_received] 1m 1w 365d 0 0 Bps 0 0 0 0 The number of bytes received from all clients. It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf. 0 MySQL 10 MySQL bytes sent per second 0 mysql.status[Bytes_sent] 1m 1w 365d 0 0 Bps 0 0 0 0 The number of bytes sent to all clients. It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf. 0 MySQL 10 MySQL begin operations per second 0 mysql.status[Com_begin] 1m 1w 365d 0 0 qps 0 0 0 0 It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf. 0 MySQL 10 MySQL commit operations per second 0 mysql.status[Com_commit] 1m 1w 365d 0 0 qps 0 0 0 0 It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf. 0 MySQL 10 MySQL delete operations per second 0 mysql.status[Com_delete] 1m 1w 365d 0 0 qps 0 0 0 0 It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf. 0 MySQL 10 MySQL insert operations per second 0 mysql.status[Com_insert] 1m 1w 365d 0 0 qps 0 0 0 0 It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf. 0 MySQL 10 MySQL rollback operations per second 0 mysql.status[Com_rollback] 1m 1w 365d 0 0 qps 0 0 0 0 It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf. 0 MySQL 10 MySQL select operations per second 0 mysql.status[Com_select] 1m 1w 365d 0 0 qps 0 0 0 0 It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf. 0 MySQL 10 MySQL update operations per second 0 mysql.status[Com_update] 1m 1w 365d 0 0 qps 0 0 0 0 It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf. 0 MySQL 10 MySQL queries per second 0 mysql.status[Questions] 1m 1w 365d 0 0 qps 0 0 0 0 It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf. 0 MySQL 10 MySQL slow queries 0 mysql.status[Slow_queries] 1m 1w 365d 0 3 0 0 0 0 It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf. 0 MySQL MySQL uptime 0 mysql.status[Uptime] 1m 1w 365d 0 3 uptime 0 0 0 0 It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf. 0 MySQL MySQL version 0 mysql.version 1h 1w 0 0 1 0 0 0 0 It requires user parameter mysql.version, which is defined in userparameter_mysql.conf. 0 MySQL MySQL performance 2 1 0 500 200 0 0 1 1 0 1 0 0 0 MySQL operations Template App MySQL 3 0 500 270 1 0 1 1 0 1 0 0 0 MySQL bandwidth Template App MySQL 3 {Template App MySQL:mysql.ping.last(0)}=0 0 MySQL is down 0 0 2 0 0 MySQL bandwidth 900 200 0.0000 100.0000 1 1 0 1 0 0.0000 0.0000 0 0 0 0 0 5 00AA00 0 2 0 Template App MySQL mysql.status[Bytes_received] 1 5 3333FF 0 2 0 Template App MySQL mysql.status[Bytes_sent] MySQL operations 900 200 0.0000 100.0000 1 1 0 1 0 0.0000 0.0000 0 0 0 0 0 0 C8C800 0 2 0 Template App MySQL mysql.status[Com_begin] 1 0 006400 0 2 0 Template App MySQL mysql.status[Com_commit] 2 0 C80000 0 2 0 Template App MySQL mysql.status[Com_delete] 3 0 0000EE 0 2 0 Template App MySQL mysql.status[Com_insert] 4 0 640000 0 2 0 Template App MySQL mysql.status[Com_rollback] 5 0 00C800 0 2 0 Template App MySQL mysql.status[Com_select] 6 0 C800C8 0 2 0 Template App MySQL mysql.status[Com_update] Service state 0 Down 1 Up