Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use zabbix to monitor multiple mysql

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use zabbix to monitor multiple mysql". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use zabbix to monitor multiple mysql".

The main tools used: macros (divided into template macros, host macros, automatic discovery macros)

Host macro format: $MACRO (you can fill in the value directly) automatically discover macros: # MACRO (the value of the key you need to cooperate with)

General architecture

1.agent host-the agent host creates the macro variable $MYSQLPORT, whose value is the auto-discovery script parameter 2 of Discovery rules. Template-create auto-discovery rules in the template, relying on the auto-discovery script to get auto-discover macro variables. 3. Monitoring item-create a monitoring item in Discovery rules. Macro variables are automatically found in the monitoring item name and key value, and the monitoring item of the relevant port is automatically generated. Client script and key creation to support the entire architecture

Build step 1. Create a template

Because this template is the default mysql monitoring template for clones, items,triggers can be ignored. The surveillance items are all in Discovery rules.

two。 Add an auto-discovery macro to the template (the way to automatically discover the macro declaration is the following script, in which only a fixed format is generated, and zabbix will assume that he is automatically discovering the macro)

The mysql.discovery in the image above is the script to get the auto-discovery macro, which is placed on the agent side.

The following are the parameters with which this script executes, and MYSQLPORT is the host macro.

The filters on the right of discovery rule means filter rules. For example, if you only want to take the so-and-so auto-discovery macro in the script, you can set it inside. There is only one auto-discovery macro, all without configuration.

3. Create monitoring items (both the monitoring item and the monitoring script need to be changed, because of the auto-discovery feature, at least one more parameter will be added to the script) 4. Create a host macro

Click on the host and add the host macro. The macro name is the parameter in the auto-discovery script, and the value of the macro is the port that needs to be monitored on this host.

This makes it possible to change the monitoring items of the host macro as long as you change the value of the host macro.

Script presentation

1.discovery_mysql.sh automatically discovers the port script (the script copied online has been modified)

Res= `echo $1 | sed "smobiles /\ nAccord g" `; 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\" {# MYSQLPORT}\ ":\" ${port [${key}]}\ "} \ n "else [[" ${key} "- eq" ((${# port [@]}-1)) "]] printf'\ t {\ n'printf"\ t\ t\ "{# MYSQLPORT}\":\ "${port [${key}]}\"\ n "fidoneprintf'\ t]\ n'printf'}\ n'

Execution example: formatting output automatically discovers macros with _ as delimiter. / discovery_mysql.sh 3306 "3307" 3308

{"data": [{"{# MYSQLPORT}": "3306"}, {"{# MYSQLPORT}": "3307"}, {"{# MYSQLPORT}": "3308"}]}

2.mysql_filestype.sh monitors some mount disks of mysql

Var=$1MYSQL_PORT=$2MYSQL_NAME= `ps-ef | grep'/ mysql/app/bin/mysqld' | grep "$MYSQL_PORT" | grep-v grep | awk-F "'{print $11}'| awk-F" / "'{print $2}'`; MYSQL_SOCk_DIR=" / $MYSQL_NAME/ "; df-h" ${MYSQL_SOCk_DIR} ${var} "| grep-v Filesystem | awk-F"'{print $5}'| awk-F"% "'{print $1}'|

3.mysql_ping.sh monitors mysql status

MYSQL_PORT=$1; ["${MYSQL_USER}" =''] & & MYSQL_USER=xxx ["${MYSQL_PASSWORD}" =''] & & MYSQL_PASSWORD=xxxxxmysqladmin=/mysql/app/bin/mysqladmin; MYSQL_SOCk_DIR= `ps-ef | grep' mysql' | grep "${MYSQL_PORT}" | grep-v 'grep' | awk-F ""' {print $16}'` ${mysqladmin}-u$ {MYSQL_USER}-p$ {MYSQL_PASSWORD} ${MYSQL_SOCk_DIR} ping 2 > / dev/null | grep 'alive' | wc-l

Note: all the connected instances here are mysql-u-p-S / xxx/mysql.sock

But later, it was found that some clients could not display the value correctly, and it was this statement that reported an error, which felt like a problem with the environment variable.

So use-socket=/xxx/mysql.sock instead of-S/xxx/mysql.sock. The variable ${MYSQL_SOCk_DIR} here is-socket=/xxx/mysql.sock.

4.mysql_repl.sh mysql master-slave status monitoring

Var=$1MYSQL_PORT=$2MYSQL_SOCk_DIR= `ps-ef | grep' mysql' | grep "${MYSQL_PORT}" | grep-v 'grep' | awk-F "' {print $16}'` Mysql=/mysql/app/bin/mysql ["${MYSQL_USER}" =''] & & MYSQL_USER=xxx ["${MYSQL_PASSWORD}" =''] & & MYSQL_PASSWORD=xxxx$ {mysql}-u$ {MYSQL_USER}-p$ {MYSQL_PASSWORD} ${MYSQL_SOCk_DIR}-e "show slave status\ G;" 2 > / dev/null | grep "\ b$ {var}\ b" | awk-F ""'{print $2}'"

The value of several ports in the master-slave state is empty, which depends on the specific setting of the problem.

Monitoring such as 5.mysql_status2 mysql performance

Mysql=/mysql/app/bin/mysqlvar=$1MYSQL_PORT=$2 ["${MYSQL_USER}" =''] & & MYSQL_USER=xxx ["${MYSQL_PASSWORD}" =''] & & MYSQL_PASSWORD=xxxxxMYSQL_SOCk_DIR= `ps-ef | grep' mysql' | grep "${MYSQL_PORT}" | grep-v 'grep' | awk-F ""' {print $16}'` ${mysql}-u$ {MYSQL_USER}-p$ {MYSQL_PASSWORD} ${MYSQL_SOCk_DIR}-e "show global status;" 2 > / dev/null | grep-v Variable_name | grep "\ b$ {var}\ b" | awk'{print $2}'

It is found that some monitoring items cannot be displayed because the numbers are too long, which need to be solved.

6.mysql_version.sh mysql version monitoring

MYSQL_PORT=$1;MYSQL_SOCk_DIR= `ps-ef | grep' mysql' | grep "${MYSQL_PORT}" | grep-v 'grep' | awk-F "' {print $16}'`; mysql=/mysql/app/bin/mysql ["${MYSQL_USER}" =''] & & MYSQL_USER=xxx ["${MYSQL_PASSWORD}" =''] & & MYSQL_PASSWORD=xxxx$ {mysql}-u$ {MYSQL_USER}-p$ {MYSQL_PASSWORD} ${MYSQL_SOCk_DIR}-e "select version ();" 2 > / dev/null | awk 'END {print}'

7.mysql_status_many.conf generates an available key profile

UserParameter=mysql.discovery [*], / patrol/zabbix/bin/duoshili_discovery/discovery_mysql.sh $1UserParameter = mysql.status_many [*], / patrol/zabbix/bin/duoshili_discovery/mysql_status2 $1 $2UserParameter=mysql.ping_many [*], / patrol/zabbix/bin/duoshili_discovery/mysql_ping.sh $1UserParameter=mysql.version_many [*], / patrol/zabbix/bin/duoshili_discovery/mysql_version.sh $1UserParameter=mysqlcheck_repl [*], / patrol/zabbix/bin/duoshili_discovery/mysql_repl.sh $1 $2UserParameter=mysql.filestyle_many [*] / patrol/zabbix/bin/duoshili_discovery/mysql_filestype Thank you for your reading The above is the content of "how to use zabbix to monitor multiple mysql". After the study of this article, I believe you have a deeper understanding of how to use zabbix to monitor multiple mysql, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report