Zabbix enterprise application-low level discovery monitoring mysql

Source: Internet
Author: User
Tags mysql create

I have introduced the use of zabbix monitoring fixed port 3306 mysql Article address for http://dl528888.blog.51cto.com/2382721/1346590), there is a bad place is only monitoring fixed port 3306, if it is not 3306 port, You need to modify the template, if the host has multiple mysql instances, you need to have different mysql templates and manage the monitoring. To solve this problem, I use lldlow level discovery to monitor mysql, you only need to mark the port to be monitored in the regular expression to monitor multiple mysql instances.

The following is monitoring:

1. Overall Diagram

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T3453324-0.jpg "title =" 4.jpg" alt = "wKioL1L4LUmCW-ESAAHS4laY7l8200.jpg"/>

We can see that I have monitored the mysql instances 3306 and 3307. In the figure, they are distinguished by ports.

Below I will only list the monitoring of port 3307

2. Mysql Sort of 3307 Port

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T345C21-1.jpg "title =" 4.jpg" alt = "wKioL1L4PQyx72s9AAOGMOegRn4968.jpg"/>

3. Mysql Bytes_sent Bytes_received of 3307 Port

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T3453X8-2.jpg "title =" 4.jpg" alt = "wKioL1L4PXCTcVI4AAQkN8eslXU927.jpg"/>

4. Mysql Com of 3307 Port

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T3452202-3.jpg "title =" 4.jpg" alt = "wKioL1L4PaXDM5gjAASHdVr_yo8936.jpg"/>

5. Mysql Connectionsof 3307 Port

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T3456053-4.jpg "title =" 4.jpg" alt = "wKioL1L4PdnA9HBSAAPNpxNZBjQ866.jpg"/>

6. Mysql Create tmp of 3307 Port

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T345H29-5.jpg "title =" 4.jpg" alt = "wKiom1L4Pj7AzZfaAAO7WH9_52I946.jpg"/>

7. Mysql Innodb of 3307 Port

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T3453c8-6.jpg "title =" 4.jpg" alt = "wKioL1L4PlGBcuf5AAQ3dJ9nqzI594.jpg"/>

8. Mysql Key of 3307 Port

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T34512A-7.jpg "title =" 4.jpg" alt = "wKiom1L4PqKw7PlLAAPwSZyt8BE566.jpg"/>

9. Mysql Qcache of 3307 Port

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T345D50-8.jpg "title =" 4.jpg" alt = "wkiol1l4prqb_nv51_exk2gxfw856.jpg"/>

10. Mysql Queries and Questions of 3307 Port

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T345IH-9.jpg "title =" 4.jpg" alt = "wkiom1l4pw6s2mbpaannwtzmy4715.jpg"/>

11. Mysql Slow of 3307 Port

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T3452609-10.jpg "title =" 4.jpg" alt = "wKioL1L4PxvDYB4-AANkCNrQFuw082.jpg"/>

12. Mysql Sort of 3307 Port

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T3452G3-11.jpg "title =" 4.jpg" alt = "wKiom1L4P2eiXVnBAAOeo53HqYE187.jpg"/>

13. Mysql Uptime of 3307 Port

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T3451115-12.jpg "title =" 4.jpg" alt = "wKioL1L4P3vwNot9AAPThSeytBA933.jpg"/>

How to implement:

I. Client

1. json-based monitoring content

In the client, the monitoring content needs to be displayed in json format, and then the server can filter the results through regular expressions.

The following is the json display of my json monitoring mysql

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T345H14-13.jpg "title =" 4.jpg" alt = "wKioL1L4QHHguC-_AABm3y8-ZIQ241.jpg"/>

The script content is as follows:

#!/bin/bash#Fucation:mysql low-level discovery#Script_name mysql_low_discovery.shdiscovery() {            port=($(sudo netstat -tpln | awk -F "[ :]+" '/[m]ysql/ && /0.0.0.0/ {print $5}'))            printf '{\n'            printf '\t"data":[\n'               for key in ${!port[@]}                   do                       if [[ "${#port[@]}" -gt 1 && "${key}" -ne "$((${#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'}discovery

Store the file in/usr/local/zabbix/bin, grant the 755 permission, modify the user and group to zabbi, and allow the zabbix user to run netstat without a password.

echo "zabbix ALL=(root) NOPASSWD:/bin/netstat">>/etc/sudoers

2. Modify the zabbix_agentd.conf File

Add the following content at the end of zabbix_agentd.conf:

UserParameter=zabbix_low_discovery,/bin/bash /usr/local/zabbix/bin/mysql_low_discovery.shUserParameter=mysql_stats[*],mysql -h localhost -P \$1 -uzabbix -pzabbix -e "show global status"|grep "\<\$2\>"|cut  -f2

3. mysql authorization

GRANT PROCESS ON *.* TO 'zabbix'@'localhost' identified BY 'zabbix';Flush privileges;

4. Restart the zabbix service.

ps -ef|grep zabbix|grep -v grep|awk '{print $2}'|xargs kill -9/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/conf/zabbix_agentd.conf

Ii. Server

1. template Import

Import the Template Mysql Auto Discovery into zabbix in the attachment). The specific operations are not described.

2. Set the Regular Expression

In "manage" = "general" = "Regular Expression", select "new regular expression"

Then, set the settings as follows:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T3451502-14.jpg "title =" 4.jpg" alt = "wKioL1L4Q6HhYgzHAAG68C970XY733.jpg"/>

I am running these 9 mysql instances from 3301 to 3309

3. Host Association Template

You can monitor the host management template of the mysql instance. The default value is automatically updated 3600 seconds later, as shown in figure

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140210/1T3455R8-15.jpg "title =" 4.jpg" alt = "wKioL1L4RA-i4NphAAJjI4nsqj4159.jpg"/>

Why set 3600 seconds? The reason is that if the setting time is too short, for example, if you set 60 s, one is the pressure on the server, and the other is that if the port you detect suddenly drops, there is no urgent alarm, if the host cannot obtain this information through json, it is deemed that there is no such port, and the content of this metric item will be automatically disabled in the template for 30 days by default, and then automatically deleted ), in this way, the alarm function is basically unavailable, so it is better to find a longer interval.


This article is from the "Yin-Technical Exchange" blog, please be sure to keep this source http://dl528888.blog.51cto.com/2382721/1357713

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.