Zabbix monitoring MySQL Multi-instance self-discovery monitoring

Source: Internet
Author: User

System Maintenance engineer Li Chao

1. Define the port for each instance

Cat Mysql_port 33063307330833093310 331133123313

2. Create a Zabbix for all instances users only allow local access, production environment specific permissions you crossing look at it. O (∩_∩) o

GRANT all privileges on * * to [e-mail protected] ' 127.0.0.1 ' identified by ' Zabbix ';

3. Create automatic discovery MySQL Port script

cat/data/prg/zabbix/scripts/discovery_mysql.sh

#!/bin/bash# -------------------------------------------------------------------------------# script _name: discovery_mysql.sh # revision:    1.0# date:         2017/03/09# Author:      kbsonlong#  email:       [email protected]# website:      www.along.party# -------------------------------------------------------------------------------Res = ' cat /data/prg/zabbix/scripts/mysql_port|grep -v  ' ^# "' port= ($res)  printf  ' {\ n '   printf  ' \ t ' data: [\ n '  for key in ${!port[@]} do     if  [[  "${#port [@]}"  -gt 1 &&  "${key}"  -ne  "$ ((${#port [@]}-1)]"  ]];then         printf  ' \t {\n '           printf  "\t\t\t\" {#MYSQLPORT}\ ": \" ${port[${key}]}\ "},\n"       else [[  "${key}"  -eq  "((${#port [@]}-1))"  ]]          printf  ' \t {\n '          printf  \t\t\t \ "{#MYSQLPORT}\": \ "${port[${key}]}\"}\n "     fi doneprintf  ' \t ]\n '  printf  '}\n '

4. Create a MySQL detection script

# cat /data/prg/zabbix/scripts/check_multimysql.sh #!/bin/bash# -------------------------- -----------------------------------------------------# filename:    check_ multimysql.sh# revision:    1.0# date:         2017/03/09# Author:      kbsonlong# Email:        [email protected]# website:     www.along.party#  License:     GPL# -------------------------------------------------------- ----------------------- #  username mysql_user= ' Zabbix '  #  password mysql_pwd= ' Zabbix '  #  host address/ ipmysql_host= ' 127.0.0.1 '  #  port mysql_port=$2 #  data connection mysql_conn= "/usr/bin/mysqladmin -u${ Mysql_user} -p${mysql_pwd} -h${mysql_host} -p${mysql_port} "# #help函数help ()  {         echo  "Usage:$0  [ping| uptime| com_update| slow_queries| Com_select| com_rollback| questions| Com_insert| com_delete| Com_commit| Bytes_sent| bytes_received| Com_begin]  port "}#  parameter is correct if [ $# -lt " 2 " ];then      echo  "parameter Missing!"     help     exit 2fi  #  Get Data case $1  in     ping)          result= ' ${ Mysql_conn} ping | grep -c alive '           echo  $result          ;;      uptime)          result= ' ${MYSQL_ Conn} status|cut -f2 -d ":" |cut -f1 -d "T"           echo  $result          ;;      com_update)          result= ' ${MYSQL_ conn} extended-status |grep -w  "Com_update" |cut -d "|"  -f3 '          echo  $result           ;;      slow_queries)          result= ' ${ Mysql_conn} status |cut -f5 -d ":" |cut -f1 -d "O"           echo  $result          ;;      com_select)          result= ' ${MYSQL _conn} extended-status |grep -w  "Com_select" |cut -d "|"  -f3 '          echo  $result                   ;;      com_rollback)          result= ' ${ mysql_conn} extended-status |grep -w  "Com_rollback" |cut -d "|"  -f3 '                   echo  $result                   ;;      questions)          result= ' ${MYSQL_ Conn} status|cut -f4 -d ":" |cut -f1 -d "S" '                   echo  $result                   ;;      com_insert)          result= ' ${MYSQL _conn} extended-status |grep -w  "CoM_insert "|cut -d" | "  -f3 '                   echo  $result                   ;;      com_delete)          result= ' ${MYSQL _conn} extended-status |grep -w  "Com_delete" |cut -d "|"  -f3 '                   echo  $result                   ;;      com_commit)          result= ' ${MYSQL _conn} extended-status |grep -w  "Com_commit" |cut -d "|"  -f3 '                   echo  $result &NBsp;                ;;      bytes_sent)          result= ' ${MYSQL _conn} extended-status |grep -w  "bytes_sent"  |cut -d "|"  -f3 '                   echo  $result                   ;;      bytes_received)          result= ' ${ mysql_conn} extended-status |grep -w  "bytes_received"  |cut -d "|"  -f3 '                   echo  $result                   ;;      com_bEgin)          result= ' ${mysql_conn} extended-status | grep -w  "Com_begin" |cut -d "|"  -f3 '                   echo  $result                   ;;                                   *)           help         ;;  esac

5. Test script is normal

# bash discovery_mysql.sh {         "Data":[          {                          "{#MYSQLPORT}": "3306"},          {                          "{#MYSQLPORT}": "3307"},          {                          "{#MYSQLPORT}": "3308 "},         {                          "{#MYSQLPORT}" : "3309"},  &Nbsp;      {                          "{#MYSQLPORT}": "3310"},          {                          "{#MYSQLPORT}": "3311"},          {                          "{#MYSQLPORT}": "3312 "},         {                          "{#MYSQLPORT}" : "3313"}         ]}# bash check_multimysql.sh  parameter missing ! Usage:check_multimysql.sH  [ping| uptime| com_update| slow_queries| Com_select| com_rollback| questions| Com_insert| com_delete| Com_commit| Bytes_sent| bytes_received| Com_begin]  port# bash check_multimysql.sh ping 33061# bash check_ multimysql.sh uptime 330618180446

6. Zabbix Agent configuration file Add custom script and restart Zabbix agent

vim/data/prg/zabbix/etc/zabbix_agentd.confuserparameter=mysql_discovery[*],/bin/bash/data/prg/zabbix/scripts/ Discovery_mysql.sh#####$1==command $2===portuserparameter=mysql.status[*],/data/prg/zabbix/scripts/check_ Mysql.sh $ userparameter=mysql.ping[*],/data/prg/zabbix/scripts/check_mysql.sh Ping

/etc/init.d/zabbix_agentd restart

7, the use of zabbix_get check the definition of the key is effective

#/usr/local/zabbix/bin/zabbix_get-s 192.168.62.200-k mysql.ping[3307] #/usr/local/zabbix/bin/zabbix_get-s 192.168 .62.200-k mysql.status[uptime,3307]18180813#/usr/local/zabbix/bin/zabbix_get-s 192.168.62.200-k mysql.status[ uptime,3306]18180842#/usr/local/zabbix/bin/zabbix_get-s 192.168.62.200-k mysql.status[uptime,3310]18180847#/usr/ Local/zabbix/bin/zabbix_get-s 192.168.62.200-k mysql.status[bytes_sent,3310]58803854473

8. Import templates Template Multi Mysql.xml


9. Monitored Host Association templates




Zabbix monitoring MySQL Multi-instance self-discovery monitoring

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.