Environment is the CentOS 6.5 x86_64 system
Zabbix version: 3.0.4
MySQL Server Version: 5.6.292 Binary Installation
The configuration file for zabbix_agentd.conf is as follows:
[Email protected] alertscripts]# cat/usr/local/zabbix/etc/zabbix_agentd.conf | Grep-v ' ^# ' | Grep-v ' ^$ '
Logfile=/tmp/zabbix_agentd.log
Enableremotecommands=1
server=10.18.3.193
listenport=10050
serveractive=10.18.3.193
hostname=10.18.3.191
Allowroot=1
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
Unsafeuserparameters=1
#下面两行是自定义的key
userparameter=mysql.slave,/usr/local/zabbix/share/zabbix/alertscripts/check_mysql_slave.sh | Grep-c ' OK '
Userparameter=mysql.status[*],/usr/local/zabbix/share/zabbix/alertscripts/mysql_server_status.sh $
To view MySQL licensing:
MySQL authorization requires a password to access, but using the password MySQL will prompt the plaintext password, there will be the following prompt:
[Email protected] alertscripts]# sh check_mysql_slave.sh
Warning:using a password on the command line interface can is insecure.
Ok-slave is running
The solution is as follows:
[Email protected] alertscripts]# CAT/ETC/MY.CNF | Tail-4
[Client]
user = root
host = localhost
Password = [email protected]
Run the script again:
[Email protected] alertscripts]# sh check_mysql_slave.sh
Ok-slave is running
MySQL master-slave monitoring script, the script to remove the user, password directly using the command.
[email protected] alertscripts]# cat check_mysql_slave.sh
#!/bin/bash
Declare-a slave_is
Slave_is= ($ (/data/mysql/bin/mysql-e "show slave Status\g" |grep-e "slave_io_running| Slave_sql_running: "|awk ' {print $} '))
If ["${slave_is[0]}" = "yes"-a "${slave_is[1]}" = "yes"];then
echo "Ok-slave is running"
Exit 0
Else
echo "Down-slave is not running"
Exit 2
Fi
Mysql_server_status script, this block above my.cnf fill, use mysqladmin also do not prompt:
[email protected] alertscripts]# cat mysql_server_status.sh
#!/bin/bash
Source/etc/profile
mysqladmin= ' which mysqladmin '
Case $ in
Uptime)
result= ' ${mysqladmin} status|cut-f2-d ":" |cut-f1-d "T" '
Echo $result
;;
Com_update)
result= ' ${mysqladmin} extended-status |grep-w "Com_update" |cut-d "|"-f3 '
Echo $result
;;
Slow_queries)
result= ' ${mysqladmin} status |cut-f5-d ":" |cut-f1-d "O"
Echo $result
;;
Com_select)
result= ' ${mysqladmin} extended-status |grep-w "Com_select" |cut-d "|"-f3 '
Echo $result
;;
Com_rollback)
result= ' ${mysqladmin} extended-status |grep-w "Com_rollback" |cut-d "|"-f3 '
Echo $result
;;
Questions)
result= ' ${mysqladmin} status|cut-f4-d ":" |cut-f1-d "S" '
Echo $result
;;
Com_insert)
result= ' ${mysqladmin} extended-status |grep-w "Com_insert" |cut-d "|"-f3 '
Echo $result
;;
Com_delete)
result= ' ${mysqladmin} extended-status |grep-w "Com_delete" |cut-d "|"-f3 '
Echo $result
;;
Com_commit)
result= ' ${mysqladmin} extended-status |grep-w "Com_commit" |cut-d "|"-f3 '
Echo $result
;;
Bytes_sent)
result= ' ${mysqladmin} extended-status |grep-w "bytes_sent" |cut-d "|"-f3 '
Echo $result
;;
bytes_received)
result= ' ${mysqladmin} extended-status |grep-w "bytes_received" |cut-d "|"-f3 '
Echo $result
;;
Com_begin)
result= ' ${mysqladmin} 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
The zabbix_server gets the key value, or the view Zabbix_server.log file can be wrong.
[Email protected] bin]#/zabbix_get-s 10.18.3.191-k Mysql.status[uptime]
zbx_notsupported:unsupported Item key.
[Email protected] bin]#/zabbix_get-s 10.18.3.191-k Mysql.status[uptime]
/usr/local/zabbix/share/zabbix/alertscripts/mysql_server_status.sh:line 4:mysqladmin:command not found
[Email protected] bin]#/zabbix_get-s 10.18.3.191-k Mysql.status[uptime]
414242
Zabbix_agent.log can see that a custom key has been obtained
Add a custom template, the template name is optional to a MySQL-related
Create an app Set
Add monitoring items, a key to add a key, the script key is added in
MySQL state this block only did a graphical view, and did not make the trigger, only do the master-slave trigger, need to add their own
Add a MySQL database to view the latest data after the addition is complete.
More content:http://www.wangzhanjianshegs.com/ website Construction
Zabbix Customizing monitoring MySQL performance status