Zabbix enterprise application-Mysql master/slave monitoring _ MySQL

Source: Internet
Author: User
Now I will introduce how to monitor the master-slave status of mysql. The following is monitoring: 1. MysqlSlaveStatusof3306Port is also monitored using lowleveldiscovery, I have merged a template with the previous lld template for mysql monitoring. now I am going to show you how to monitor the master-slave status of mysql.

The following is monitoring:

1. Mysql Slave Status of 3306 Port

This is also the use of low level discovery for monitoring, and has merged a template with the previous lld monitoring mysql template (so this article will only introduce the mysql master/slave status, other performance, in this way, a template can monitor both mysql Performance and mysql master/slave status automatically. if I/O or SQL is not in the yew status, an alarm is triggered.

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

The script content is as follows:

 
 
  1. #!/bin/bash
  2. #Fucation:mysql low-level discovery
  3. #Script_name mysql_low_discovery.sh
  4. mysql() {
  5. port=($(sudo netstat -tpln | awk -F "[ :]+" '/[m]ysql/ && /0.0.0.0/ {print $5}'))
  6. printf '{\n'
  7. printf '\t"data":[\n'
  8. for key in ${!port[@]}
  9. do
  10. if [[ "${#port[@]}" -gt 1 && "${key}" -ne "$((${#port[@]}-1))" ]];then
  11. socket=`ps aux|grep ${port[${key}]}|grep -v grep|awk -F '=' '{print $10}'|cut -d ' ' -f 1`
  12. printf '\t {\n'
  13. printf "\t\t\t\"{#MYSQLPORT}\":\"${port[${key}]}\"},\n"
  14. else [[ "${key}" -eq "((${#port[@]}-1))" ]]
  15. socket=`ps aux|grep ${port[${key}]}|grep -v grep|awk -F '=' '{print $10}'|cut -d ' ' -f 1`
  16. printf '\t {\n'
  17. printf "\t\t\t\"{#MYSQLPORT}\":\"${port[${key}]}\"}\n"
  18. fi
  19. done
  20. printf '\t ]\n'
  21. printf '}\n'
  22. }
  23. $1

Store the file in/usr/local/zabbix/bin, Grant 755 permissions, modify the user and group to zabbix, and allow zabbix users to run netstat without a password.

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

# Disable requiretty

 
 
  1. sed -i 's/^Defaults.*.requiretty/#Defaults requiretty/' /etc/sudoers

If it is not disabled, data cannot be obtained and the zabbix log reports

2. modify the zabbix_agentd.conf file

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

 
 
  1. UserParameter=zabbix_low_discovery[*],/bin/bash /usr/local/zabbix/bin/mysql_low_discovery.sh $1
  2. UserParameter=mysql_stats[*],mysql -h localhost -P $1 -uzabbix -pzabbix -e "show global status"|grep "\<$2\>"|cut -f2
  3. UserParameter=mysql_stats_slave[*],mysql -h localhost -P $1 -uzabbix -pzabbix -e "show slave status\G"|grep "\<$2\>"|awk '{if($NF=="Yes") {print 1} else {print 0}}'

3. test

If you can use/usr/local/zabbix/bin/zabbix_get-s 127.0.0.1-k Runtime [mysql] and/usr/local/zabbix/bin/zabbix_get-s 127.0.0.1-k mysql_stats_slave [3306, slave_IO_Running],/usr/local/zabbix/bin/zabbix_get-s 127.0.0.1-k mysql_stats_slave [3306, Slave_ SQL _Running] command to obtain data indicates no problem. The following is my test result

4. mysql authorization

 
 
  1. GRANT PROCESS,REPLICATION CLIENT ON *.* TO 'zabbix'@'localhost' identified BY 'zabbix';
  2. Flush privileges;

5. restart the zabbix service.

 
 
  1. ps -ef|grep zabbix|grep -v grep|awk '{print $2}'|xargs kill -9
  2. /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 (the Template is included 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:

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

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 this port is not available. the content of this metric item is automatically disabled in the template (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.

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.