Get the App
SLTechnology News&Howtos  ›  Database  › 

Zabbix3.0.4 monitors the status of MySQL database

Shulou Source: shulou.com Published: 2022-06-01 09:15:44 10月02日 Update

First configure the information of the MySQL server on the zabbix host, add the Template App MySQL template that comes with zabbix, then install agent on the mysql server, and then add the mysql monitoring script.

The template Template App MySQL for monitoring mysql provided officially by 1.Zabbix can see the relevant Items and key.

Open the monitoring item to view the added mysql template

The 2.zabbix_agent side writes a Shell script combined with the official key to extract the key value of Items from the database.

Cat checkmysql.sh

#! / bin/bash

MYSQLADMIN=mysqladmin

MYSQL_SOCK= "/ tmp/mysql.sock"

MYSQL_USER=*

MYSQL_PWD=*

ARGS=1

If [$#-ne "$ARGS"]; then

Echo "Please input one arguement:"

Fi

Case $1 in

Uptime)

Result= `$ {MYSQLADMIN}-u$ {MYSQL_USER}-p$ {MYSQL_PWD}-S $MYSQL_SOCK status | cut-f2-d ":" | cut-F1-d "T" `

Echo $result

Com_update)

Result= `$ {MYSQLADMIN}-u$ {MYSQL_USER}-p$ {MYSQL_PWD}-S $MYSQL_SOCK extended-status | grep-w "Com_update" | cut-d "|"-f3`

Echo $result

Slow_queries)

Result= `$ {MYSQLADMIN}-u$ {MYSQL_USER}-p$ {MYSQL_PWD}-S $MYSQL_SOCK status | cut-f5-d ":" | cut-F1-d "O" `

Echo $result

Com_select)

Result= `$ {MYSQLADMIN}-u$ {MYSQL_USER}-p$ {MYSQL_PWD}-S $MYSQL_SOCK extended-status | grep-w "Com_select" | cut-d "|"-f3`

Echo $result

Com_rollback)

Result= `$ {MYSQLADMIN}-u$ {MYSQL_USER}-p$ {MYSQL_PWD}-S $MYSQL_SOCK extended-status | grep-w "Com_rollback" | cut-d "|"-f3`

Echo $result

Questions)

Result= `$ {MYSQLADMIN}-u$ {MYSQL_USER}-p$ {MYSQL_PWD}-S $MYSQL_SOCK status | cut-f4-d ":" | cut-F1-d "S" `

Echo $result

Com_insert)

Result= `$ {MYSQLADMIN}-u$ {MYSQL_USER}-p$ {MYSQL_PWD}-S $MYSQL_SOCK extended-status | grep-w "Com_insert" | cut-d "|"-f3`

Echo $result

Com_delete)

Result= `$ {MYSQLADMIN}-u$ {MYSQL_USER}-p$ {MYSQL_PWD}-S $MYSQL_SOCK extended-status | grep-w "Com_delete" | cut-d "|"-f3`

Echo $result

Com_commit)

Result= `$ {MYSQLADMIN}-u$ {MYSQL_USER}-p$ {MYSQL_PWD}-S $MYSQL_SOCK extended-status | grep-w "Com_commit" | cut-d "|"-f3`

Echo $result

Bytes_sent)

Result= `$ {MYSQLADMIN}-u$ {MYSQL_USER}-p$ {MYSQL_PWD}-S $MYSQL_SOCK extended-status | grep-w "Bytes_sent" | cut-d "|"-f3`

Echo $result

Bytes_received)

Result= `$ {MYSQLADMIN}-u$ {MYSQL_USER}-p$ {MYSQL_PWD}-S $MYSQL_SOCK extended-status | grep-w "Bytes_received" | cut-d "|"-f3`

Echo $result

Com_begin)

Result= `$ {MYSQLADMIN}-u$ {MYSQL_USER}-p$ {MYSQL_PWD}-S $MYSQL_SOCK extended-status | grep-w "Com_begin" | cut-d "|"-f3`

Echo $result

*)

Echo "Usage:$0 (Uptime | Com_update | Slow_queries | Com_select | Com_rollback | Questions)"

Esac

3. Add UserParameter to Zabbix_agentd.conf in the following format. For Zabbix, a script is actually a plug-in.

Vim / usr/local/zabbix-3.0.4/etc/zabbix_agentd.conf# enables user-defined configuration UnsafeUserParameters=1

# add mysql Monitoring

Arameter=mysql.version,mysql-V

UserParameter=mysql.ping,mysqladmin-upright bands *-paired boxes *-S / tmp/mysql.sock

Ping | grep-c alive

3.UserParameter=mysql.status [*], / usr/local/zabbix_agent/bin/checkmysqlperformance.sh $1 $2

4. Restart the agentd server, and then use zabbix_get in zabbix server to get the key value.

5. In the front end of zabbix, you can view the number of operations per second of SQL statements in real time.

6. Summary

Put the script on the server to be monitored (Modify mysql user and password), modify the parameters of UserParameter and restart the Template App MySQL template provided officially by agentd,Link.

I am using the root account in the test environment. During the security of the online server, you can grant readonly permissions to mysql users.

According to the actual requirements, in addition to monitoring the above monitoring items, you can also monitor mysql processlist,Innodb and so on.

7. There are problems in it.

Resulting in the following figure

Add to my.cnf

[mysqladmin]

User=root

Password=*

(at this time, as long as you do not need to add a password after the mysqladmin, you can directly follow the command mysqladmin ping | grep-c alive)

Restart zabbix_agent retest will not make an error

Tags: Monitoring server service script official template user test configuration data database security following figure host information front end parameters commands real-time actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MySQL Apple vpn Shulou Tech Info