Zabbix automatically discovers MySQL ports and monitors

Source: Internet
Author: User

First, demand:

Because we are a game business, to use MySQL, a server running multiple MySQL instances is also very normal. Adding web monitoring is too time-consuming if you modify agent.conf manually on a single station. So just think about using Zabbix's automatic discovery to monitor

Second, the configuration agent

1. Writing the Autodiscover port script

[[email protected] ~]# cat /etc/zabbix/alertscripts/zabbix_discovery_mysql.sh #!/bin/ Bashmysql ()  {            port= ($ (sudo  netstat -tpln | awk -f  "[ :]+"   '/[m]ysql/'  | awk -F:  ' { print $4} ')             printf  ' {\ n '             printf  ' \ t ' data: [\ n '                 for key in ${! port[@]}                    do                        if [[  "${#port [@]}"  -gt 1 &&  " ${key} " -ne&nbSP; " $ ((${#port [@]}-1)]  ]];then               socket= ' ps aux|grep ${port[${key}]}|grep -v grep|awk -f  ' = '   ' {print  $10} ' |cut -d  '   '  -f 1 '                            printf   ' \t {\n '                            printf  "\t\t\t\" {#MYSQLPORT}\ ": \" ${port [${key}]} \ "},\n"                       else [[  "${key}"  -eq  "((${#port [@]}-1))"  ]]               socket= ' Ps aux|grep ${port[${key}] }|grep -v grep|awk -F  ' = '   ' {print $10} ' |cut -d  '   '  -f 1 '                            printf  ' \t {\n '                             printf  "\t\t\t\" {#MYSQLPORT}\ ": \" ${port[${key}]}\ "}\n"                         fi                done                            printf  ' \t ]\n '                            printf  '}\n '}$1 

2. Empowering

Assign Execute permission chmod 755/etc/zabbix/alertscripts/zabbix_discovery_mysql.sh modify genus Group Chown zabbix.zabbix/etc/zabbix/alertscripts/ zabbix_discovery_mysql.sh

3. Test the script effect

[Email protected] ~]#/etc/zabbix/alertscripts/zabbix_discovery_mysql.sh mysql{"Data": [{ "{#MYSQLPORT}": "3306"}]}

4. Configure agent.conf

[Email protected] ~]# cat/etc/zabbix/zabbix_agentd.conf | grep include### option:include# include=# include=/usr/local/etc/zabbix_agentd.userparams.conf# Include=/usr/local/ Etc/zabbix_agentd.conf.d/include=/etc/zabbix/zabbix_agentd.conf.d/*.conf
[email protected] zabbix_agentd.conf.d]# cat check_mysql.conf userparameter=mysql.discovery[*],/etc/zabbix/ alertscripts/zabbix_discovery_mysql.sh $1userparameter=mysql_stats[*],/usr/bin/mysql--defaults-file=/home/ Zabbix/.my.cnf-p $1-e "Show Global Status" |grep "\<$2\>" |cut-f2

5.sudo Permissions

#Defaults Requirettydefaults:zabbix!requirettyzabbix all= (Root) nopasswd:/bin/netstat,/usr/bin/mysql

6. Create Zabbix query MySQL user

GRANT PROCESS on *. Zabbix ' @ ' localhost ' identified by ' Zabbix '; Flush privileges;

Note: warning:using a password on the command line interface can is insecure.

Because mysql5.6 cannot log in with a plaintext password, a file is created here to specify the user name password

7. Create a MYSQL.CNF file

[Email protected] zabbix]# CAT/HOME/ZABBIX/.MY.CNF [client]user=zabbixpassword=zabbixhost=localhost
Chown Zabbix.zabbix/home/zabbix/.my.cnfchmod 600/home/zabbix/.my.cnf

8. Restart Agent Service

Service Zabbix_agentd Restart

9. Testing

[Email protected] alertscripts]#/usr/local/zabbix/bin/zabbix_get-s 127.0.0.1-k mysql_stats[3306,uptime]3862[[         Email protected] alertscripts]#/usr/local/zabbix/bin/zabbix_get-s 127.0.0.1-k mysql.discovery[mysql]{"Data": [ {"{#MYSQLPORT}": "3306"}]}


Third, configure the Web

    1. Add a template


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/89/C3/wKiom1gb8lPw46j_AABXERmpMik442.png "title=" 9c2ed3f8-afb2-439b-9d5d-9f7e8b095d3a.png "alt=" Wkiom1gb8lpw46j_aabxermpmik442.png "/>


2. Create an App


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/89/C1/wKioL1gb8oKwiNNFAABCxlwXGvo462.png "title=" 37dc5ab3-322e-4f87-b942-7c172a4bcb5c.png "alt=" Wkiol1gb8okwinnfaabcxlwxgvo462.png "/>


3. Create an Autodiscover rule


650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/89/C1/wKioL1gb8qaRQkWPAABo6IY2yaU666.png "title=" F39b65b6-0030-4ff5-8a7e-c304bc02ea92.png "alt=" Wkiol1gb8qarqkwpaabo6iy2yau666.png "/>


4. Create a monitoring item


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/89/C3/wKiom1gb8sWixaC_AACbL6A-5Ic397.png "title=" Bdd2f2f6-0962-4906-9a09-b91075f5d641.png "alt=" Wkiom1gb8swixac_aacbl6a-5ic397.png "/>

5. Create a graphic


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/89/C3/wKiom1gb8t2BzqUaAACdXx_ToXc854.png "title=" 77baee71-a439-4626-9331-d5c27d767f95.png "alt=" Wkiom1gb8t2bzquaaacdxx_toxc854.png "/>

6. Host link templates


7. View monitoring data

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/89/C3/wKiom1gb8vzSVdckAAB6IawU660105.png "title=" 39a93ce2-c97b-49dd-8399-3ee5edb21090.png "alt=" Wkiom1gb8vzsvdckaab6iawu660105.png "/>

This article from "Do not abandon!" Do not give up "blog, be sure to keep this source http://thedream.blog.51cto.com/6427769/1869233

Zabbix automatically discovers MySQL ports and monitors

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.