參考 http://www.linuxidc.com/Linux/2016-04/130436.htm前端
環境:mysql
zabbix sever: 192.168.234.131linux
mysql :192.168.234.130sql
mysql 客戶端操做:ide
1 添加監控用戶,登入到數據裏而後:spa
GRANT USAGE ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY 'zabbix' WITH GRANT OPTION; MariaDB [(none)]> flush privileges; ##刷新系統受權 MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'zabbix' with grant option;
2 編寫腳本 vi /usr/local/zabbix/scripts/mysql_status.sh3d
User='zabbix' Password='zabbix' Mysql='/usr/bin/mysql' Mysqladmin='/usr/bin/mysqladmin' command(){ $Mysql -u $User -p$Password -e "show global status" | awk '$1 ~ /'"$1"'$/ {print $2}' } case $1 in Com_select) command $1 ;; Com_insert) command $1 ;; Com_update) command $1 ;; Com_delete) command $1 ;; Com_begin) command $1 ;; Com_commit) command $1 ;; Com_rollback) command $1 ;; Questions) command $1 ;; Slow_queries) command $1 ;; Bytes_received) command $1 ;; Bytes_sent) command $1 ;; Uptime) command $1 ;; Version) $Mysql -V | awk -F '[ ,]' '{print $6}' ;; Ping) $Mysqladmin -u$User -p$Password ping | wc -l ;; *) echo "Usage: $0 { Com_select|Com_insert|Com_update|Com_delete|Com_begin|Com_commit|Com_rollback|Questions|Slow_queries|Bytes_received|Bytes_sent|Ping|Uptime|Version }" ;; esac
三、添加自定義 key 配置文件
rest
vi /usr/local/zabbix/etc/zabbix_agentd.conf UserParameter=mysql.status[*],/usr/local/zabbix/scripts/mysql_status.sh $1 UserParameter=mysql.ping,/usr/local/zabbix/scripts/mysql_status.sh Ping UserParameter=mysql.version,/usr/local/zabbix/scripts/mysql_status.sh Version
4 重啓zabbix_agentd服務xml
/etc/init.d/zabbix_agentd restarthtm
5 最後能夠在服務端驗證
zabbix_get -s 192.168.234.130 -k mysql.ping
若是返回1便是正常
6 添加zabbix自帶的mysql模板,確認出圖
1)在zabbix前端能夠實時查看mysql發送接收的字節數。其中bytes received表示從全部客戶端接收到的字節數,bytes sent表示發送給全部客戶端的字節數。
2)實時查看SQL語句每秒鐘的操做次數