When MySQL has multiple instances on a single server, MySQL occupies multiple different ports. Low-level discovery with Zabbix can be easily monitored.
Idea Reference: http://dl528888.blog.51cto.com/2382721/1357713
Below I have written a simple script for one-click deployment of MySQL monitoring.
first, the client
Run this script on the monitored side, the prerequisites are already installed Zabbix agent (recommended yum installation). The script has been tested and passed in the CentOS6.2 x86_64 environment. The script is available for download in the attachment.
#!/bin/sh## filename: automonitormysql.sh# revision: 1.0# date: 2014/08/12# author: qicheng# email:# website: http:// Qicheng0211.blog.51cto.com/# description: zabbix low level discovery Monitoring mysql# notes: run this script on the monitored client, the prerequisites are already installed zabbix agent#root_uid=0if [ "$UID" -ne "$ROOT _uid" ];then echo "error: must run this program with the root user!" " exit 1fiagent_conf="/etc/zabbix/zabbix_agentd.conf "mkdir -p /etc/ zabbix/monitor_scripts# Create mysql low-level discovery Script Cat > /etc/zabbix /monitor_scripts/mysql_port_discovery.sh << ' EOF ' #!/bin/bash#function: mysql Low-level discovery#script_name: mysql_port_discovery.shmysql () &NBSP;{&NBSP;&Nbsp; port= (' sudo /bin/netstat -tpln | awk -f ' [ :]+ ' ' BEGIN &NBSP;{IGNORECASE=1;&NBSP;}&NBSP;/MYSQL/&NBSP;&&&NBSP;/0.0.0.0/&NBSP;{PRINT&NBSP;$5} ") max_index=$[${#port [@]}-1] printf ' {\ n ' printf ' \ t ' data: [' for key in ' seq -s ' ' 0 $max _ Index ' do printf ' \n\t\t{' printf "\" {#MYSQLPORT}\ ": \" ${port[${key}]}\ "}" if [ $key -ne $max _index ];then printf "," fi done printf ' \n\t]\n ' printf '}\n '}$ 1eofchown -r zabbix:zabbix /etc/zabbix/monitor_scriptschmod +x /etc/zabbix/monitor_scripts/mysql_port_discovery.sh# Determine if the configuration file exists [ -f "${agent_conf}" ] | | { echo "File ${agent_conf} does not exist."; exit 1;} Include= ' grep ' ^include ' ${agent_conf} | cut -d ' = ' -f2 ' # add custom parameters to the configuration file if [ -d "$include" ];then cat > $include/mysql_lld.conf << ' EOF ' userparameter=mysql_port_discovery[*],/bin/bash /etc/zabbix/monitor_scripts/ Mysql_port_discovery.sh $1userparameter=mysql_status[*],mysql -h 127.0.0.1 -p $1 -uzabbix -pzabbix -N -e "show global status where variable _name= ' $ ' " | cut -f2userparameter=mysql_ping[*],mysqladmin -h 127.0.0.1 -p $1 -uzabbix -pzabbix ping | grep -c aliveeofelse grep -q ' ^userparameter=mysql_port_discovery ' ${agent_conf} | | cat >> ${AGENT_CONF} << ' EOF ' userparameter=mysql_port_discovery[*],/bin/ bash /etc/zabbix/monitor_scripts/mysql_port_discovery.sh $1userparameter=mysql_status[*],mysql -h 127.0.0.1 -p $1 -uzabbix -pzabbix -n -e "show global Status where variable_name= ' $ ' | cut -f2userparameter=mysql_ping[*], mysqladmin -h 127.0.0.1 -p $1 -uzabbix -pzabbix ping | grep -c aliveeoffi# manual MySQL Authorization, add Zabbix account echo "Please add Zabbix account to all MySQL instances, execute > grant process ON *.* TO ' Zabbix ' @ ' 127.0.0.1 ' identified BY ' Zabbix ';flush privileges; " # Restart Agent service [ -f '/etc/init.d/zabbix-agent ' ] && /etc/init.d/zabbix-agent restart | | echo&nbsP; " The Zabbix agent service needs to be restarted manually. " # authorized Zabbix user without password run netstat command chmod +w /etc/sudoers sed -i ' s/^\ (defaults\s\+ requiretty\)/#\1/' /etc/sudoersgrep -q ' ^zabbix all= (All). *netstat ' /etc/sudoers | | echo ' zabbix all= (All) nopasswd: /bin/netstat ' >> /etc/sudoerschmod 440 /etc/sudoers# Close Selinuxsetenforce 0sed -i '/^selinux=/c\selinux=disabled ' /etc/sysconfig/selinuxsed -i '/^selinux=/c\selinux= Disabled ' /etc/selinux/config
After the script is executed, you will also need to manually MySQL authorization to add the Zabbix account to all instances:
Mysql> GRANT PROCESS on * * to ' Zabbix ' @ ' 127.0.0.1 ' identified by ' Zabbix ';mysql> flush privileges;
Perform the Zabbix_get command test on the Zabbix server side:
shell# zabbix_get-s 115.238.xxx.xxx-k ' mysql_port_discovery[mysql] ' {"Data": [{"{#MYSQLPORT}": "3306"}]}she ll# zabbix_get-s 115.238.xxx.xxx-k ' mysql_status[3306,uptime] ' 1295092shell# zabbix_get-s 115.238.xxx.xxx-k ' Mysql_ PING[3306] ' 1
Can return data, indicating that the client's MySQL monitoring is deployed.
second, web-side
1. Import Templates
After downloading the attachment template file (templates App MySQL used lld.xml), import into Zabbix.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/45/B6/wKioL1Pp4kSyoHKjAAGXWh7Zy8s473.jpg "title=" Import.png "alt=" Wkiol1pp4ksyohkjaagxwh7zy8s473.jpg "/>
2. Create a host and link the template
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/45/B5/wKiom1Pp4cShB-e7AAGzKCOtQms583.jpg "title=" Link.png "alt=" Wkiom1pp4cshb-e7aagzkcotqms583.jpg "/>
3. Data Display
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/45/B6/wKioL1Pp42OwPPWPAAbiWNEsyIs158.jpg "title=" Play.png "alt=" Wkiol1pp42owppwpaabiwnesyis158.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/45/B5/wKiom1Pp5c3TKkJoAAQ8Pf6e16I805.jpg "title=" Traffic.png "alt=" Wkiom1pp5c3tkkjoaaq8pf6e16i805.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/45/B6/wKioL1Pp5yzSM7j0AAUMjs2XGA0952.jpg "title=" Opt.png "alt=" Wkiol1pp5yzsm7j0aaumjs2xga0952.jpg "/>
This article is from the "Departure-linux Technology Blog" blog, please be sure to keep this source http://qicheng0211.blog.51cto.com/3958621/1539101