Zabbix Automatic discovery monitors multiple MySQL

Source: Internet
Author: User

1: Preface

As a result of the blog written earlier, Zabbix automatic discovery monitoring Redis, Zabbix automatic discovery monitoring MONGO These two blog posts can be automatically discovered and monitored, but because each zabbix_agentd has to be configured, monitoring is very inconvenient, so, then made a template, Ability to automatically discover and monitor multiple MySQL units. This method is also applicable when monitoring MONGO, Redis, or MySQL master and slave.


2: Write a script that automatically discovers and monitors multiple MySQL scripts under Zabbix_agentd, with the following script:

#!/bin/sh

#zhuangweihong 20160512 Zabbix Discover MySQL


mysqlconf= ' cat/usr/local/zabbix/mysql.conf|grep-v ' ^# '

Mysqlcount= ' echo ' ${mysqlconf} ' |wc-l '


If [-Z ' $mysqlconf ']];then

echo "MySQL has not find"

Exit 2

Fi


printf ' {\ n '

printf ' \ t ' data: [\ n '

Mycount=1

echo "$mysqlconf" |while read Line;do

Myip= ' echo $line |awk ' {print $} '

Myport= ' echo $line |awk ' {print $} '

If [$mysqlcount-eq $mycount];then

printf "\t\t\t{\" {#MYSQLIP}\ ": \" $myip \ ", \" {#MYSQLPORT}\ ": \" $myport \ "}\n"

Else

printf "\t\t\t{\" {#MYSQLIP}\ ": \" $myip \ ", \" {#MYSQLPORT}\ ": \" $myport \ "},\n"

Let "mycount++"

Fi

Done


printf ' \t]\n '

printf '}\n '

Exit 0


Where the configuration file vim/usr/local/zabbix/mysql.conf, the first parameter is IP, the second parameter is port, for example:

192.168.0.1 3306

192.168.0.2 3306


3: Add the following configuration in Zabbix_agentd:

userparameter=zabbix.discovery.mysql.all,/usr/local/zabbix/zabbix_discover_mysql.sh

Userparameter=mysql.status.all[*],mysql-h $3-p$1-e "Show Global Status" |grep "$2[[:space:]" |cut-f2


Precautions:

1:MYSQL.CNF can be configured with a user name and password, if configured as follows:

User=zabbix

Password=xxxxx

2: The monitor must have the usage permission on the machine, the command is as follows:

Grant Usage on * * to [e-mail protected] ' 192.168.0.99 ' identified by ' xxxxx ';

192.168.0.99 configured as Zabbix_agentd IP

3: Zabbix_agentd Restart after configuration is complete


4: Add Autodiscover template to Zabbix_server's page: MySQL Discovery Service all.


5: Add Autodiscover rule, name and key values as follows: MySQL Discovery Service all, Zabbix.discovery.mysql.all. Set to 15 minutes to discover, the failed discovery is retained for one day. The configuration is as follows:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/80/03/wKioL1c0YoviUacKAAA8xH4xNpM482.png "title=" Mysql.png "alt=" Wkiol1c0yoviuackaaa8xh4xnpm482.png "/>


6: Create a monitoring item prototype with the following name and key values:

{#MYSQLIP}/{#MYSQLPORT}:mysql Bytes sent per second mysql.status.all[{#MYSQLPORT},bytes_sent,{#MYSQLIP}]

{#MYSQLIP}/{#MYSQLPORT}:mysql Bytes received per second mysql.status.all[{#MYSQLPORT},bytes_received,{#MYSQLIP}]

{#MYSQLIP}/{#MYSQLPORT}:mysql service is running net.tcp.service[tcp,{#MYSQLIP},{#MYSQLPORT}]

Monitor the items you want to monitor.


The section diagram is as follows:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/80/03/wKioL1c0ZJ_AkGpcAACJpTtEb5k923.png "title=" Mysql_ Xiangmu.png "alt=" Wkiol1c0zj_akgpcaacjptteb5k923.png "/>


7: How do I extend it?

If you want to monitor more than one MySQL, just vim/usr/local/zabbix/mysql.conf add the MySQL IP and MySQL port you want to monitor, and then on the corresponding MySQL grant usage on * * to [ Email protected] ' 192.168.0.99 ' identified by ' xxxxx '; Zabbix will automatically detect and monitor, if you suddenly do not want to monitor the configuration on the removal, wait a day after the Zabbix will be deleted.

This article is from the "Zhangweihong" blog, make sure to keep this source http://zhuangweihong.blog.51cto.com/8808431/1772790

Zabbix Automatic discovery monitors multiple MySQL

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.