Zabbix monitors mysql instance method

Zabbix monitors mysql instance method

1. Monitoring planning

Before creating a monitoring item, you should try to consider clearly what to monitor, how to monitor, how to store the monitoring data, how to display the monitoring data, how to handle alarms, etc. To plan a monitoring system, you need to have a good understanding of Zabbix. Here we only put forward the monitoring requirements.

Requirement 1: Monitor the status of MySQL and issue an alarm when the status is abnormal;

Requirement 2: Monitor MySQL operations and display them in charts;

2. Custom script monitoring extension Agent

The collection of monitoring data between Zabbix Server and Agent is mainly through Zabbix Server actively asking Agent for the value of a key. Agent will call the corresponding function according to the key to obtain the value and return it to the Server. The Zabbix 2.4.7 Agent does not have a built-in MySQL monitoring function (but the server provides the corresponding Template configuration), so we need to use the User Parameters function of Zabbix to add a monitoring script for MySQL.

3. Authorize MySQL login user (agent side)

mysql> grant usage on *.* to [email protected] identified by '123456';

mysql> flush privileges;

4. Agent configuration

Survival detection

Use the UserParameter parameter to customize the Agent Key.
For requirement 1, we use the mysqladmin tool to implement it. The command is as follows:

# mysqladmin -h 127.0.0.1 -u zabbix -p123456 ping 
mysqld is alive

If the MySQL status is normal, it will display mysqld is alive, otherwise it will prompt that the connection cannot be made. For the server side, sentences like mysqld is alive are difficult to understand. It is best for the server to only receive 1 and 0, 1 means the service is available, and 0 means the service is unavailable. Then improve this command as follows:

# mysqladmin -h 127.0.0.1 -u zabbix -p123456 ping |grep -c alive
1

Putting the username and password in the command is not good for future maintenance, so we create a configuration file ".my.cnf" containing the MySQL username and password under /var/lib/zabbix/, as follows:

user=zabbix
host=127.0.0.1
password='123456'

With this file, the command changes to

HOME=/var/lib/zabbix/mysqladmin ping |grep -c alive
1

After completing this step, all you need to do is add this monitoring command to Zabbix Agent and correspond it to a Key, so that Zabbox Server can obtain the status of MySQL through this Key. We use mysql.ping as the key for MySQL status.

First, remove /etc/zabbix/zabbix_agentd.conf

Comment out the line “Include=/etc/zabbix_agentd.d/”.

Secondly, create the userparameter_mysql.conf file in the /etc/zabbix/zabbix_agentd.d/ directory. Add the following command to the file:

UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive

Use the following command to test whether it works properly.

# /usr/sbin/zabbix_agentd -t mysql.ping
mysql.ping [t|1]

Other performance indicators

1. Add userparameter_mysql

vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf

####Script for monitoring mysql performance UserParameter=mysql.status[*],/etc/zabbix/zabbix_agentd.d/check_mysql.sh $1

#####mysql version UserParameter=mysql.version,mysql -V

2.check_mysql.sh

#!/bin/bash
# -------------------------------------------------------------------------------
# FileName: check_mysql.sh
# Revision: 1.0
# -------------------------------------------------------------------------------
# Copyright:
# License: GPL

# Username MYSQL_USER = 'zabbix'

# Password MYSQL_PWD = 'zabbix@123'

# Host address/IP
MYSQL_HOST='ip'

# Port MYSQL_PORT = '3306'

#Data connection MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"

# Are the parameters correct? if [ $# -ne "1" ]; then
echo "arg error!"
fi

# Get data case $1 in
Uptime
result=`${MYSQL_CONN} status 2>/dev/null |cut -f2 -d":"|cut -f1 -d"T"`
echo $result
;;
Com_update)
result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_update"|cut -d"|" -f3`
echo $result
;;
Slow_queries
result=`${MYSQL_CONN} status 2>/dev/null |cut -f5 -d":"|cut -f1 -d"O"`
echo $result
;;
Com_select)
result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_select"|cut -d"|" -f3`
echo $result
;;
Com_rollback)
result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_rollback"|cut -d"|" -f3`
echo $result
;;
Questions)
result=`${MYSQL_CONN} status 2>/dev/null |cut -f4 -d":"|cut -f1 -d"S"`
echo $result
;;
Com_insert)
result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_insert"|cut -d"|" -f3`
echo $result
;;
Com_delete)
result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_delete"|cut -d"|" -f3`
echo $result
;;
Com_commit)
result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_commit"|cut -d"|" -f3`
echo $result
;;
Bytes_sent)
result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Bytes_sent" |cut -d"|" -f3`
echo $result
;;
Bytes_received)
result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Bytes_received" |cut -d"|" -f3`
echo $result
;;
Com_begin)
result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_begin"|cut -d"|" -f3`
echo $result
;;

*)
echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)"
;;
esac

3. Authorization:

chmod +x /etc/zabbix/zabbix_agentd.d/check_mysql.sh

Chown zabbix.zabbix /etc/zabbix/zabbix_agentd.d/check_mysql.sh

4. Test on zabbix_agent:

zabbix_agentd -t mysql.ping

insert image description here

5. Zabbix_server test

zabbix_get -s ip -P port -k mysql.ping

insert image description here

5. Configure on the web

**Creating a Host**

insert image description here

insert image description here

Associated templates

insert image description here

Create monitoring items

Create a graph


View surveillance images

Other monitoring items are completed with this configuration

6. Zabbix comes with MySQL monitoring items

version: database version key_buffer_size: index buffer size of MyISAM sort_buffer_size: sorting space of the session (one will be requested for each thread)
join_buffer_size: This is the minimum buffer size allocated for connection operations. These connections use normal index scans, range scans, or connections that do not apply indexes. max_connections: The maximum number of simultaneous connections allowed max_connect_errors: The maximum number of error connections allowed for a host. If exceeded, subsequent connections will be rejected (default 100). You can use the flush hosts command to remove the rejection of open_files_limits: the number of files that the operating system allows MySQL to open. You can determine whether you need to increase table_open_cache by the opened_tables status. If opened_tables is relatively large and is still increasing, it means that you need to increase table_open_cache
max-heap_tables_size: The maximum size of the memory table created (default 16M). This parameter and tmp_table_size together limit the maximum value of the internal temporary table (take the smaller of the two parameters). If the limit is exceeded, the table will be changed to innodb or myisam engine (before 5.7.5, the default is myisam, and starting from 5.7.6, it is innodb, which can be adjusted by the internal_tmp_disk_storage_engine parameter).
max_allowed_packet: Maximum size of a packet##########GET INNODB INFO
#INNODB variables
innodb_version:
innodb_buffer_pool_instances: Divide the innodb buffer pool into specified multiple instances (default is 1)
innodb_buffer_pool_size: innodb buffer pool size, 5.7.5 introduced innodb_buffer_pool_chunk_size,
innodb_doublewrite: whether to enable doublewrite (enabled by default)
innodb_read_io_threads: the number of IO read threads innodb_write_io_threads: the number of IO write threads########innodb status
innodb_buffer_pool_pages_total: the number of innodb buffer pool pages, the size is equal to innodb_buffer_pool_size/(16*1024)
innodb_buffer_pool_pages_data: the number of pages containing data in the innodb buffer pool########## GET MYSQL HITRATE
1. Query cache hit rate: If Qcache_hits+Com_select<>0, then it is Qcache_hits/(Qcache_hits+Com_select), otherwise it is 0

2. Thread cache hit rate: If Connections<>0, then it is 1-Threads_created/Connections, otherwise it is 0

3. MyISAM key cache hit rate is 1-Key_reads/Key_read_requests if Key_read_requests<>0, otherwise it is 0

4. MyISAM key cache write hit rate is 1-Key_writes/Key_write_requests if Key_write_requests<>0, otherwise it is 0

5. Key block usage rate: If Key_blocks_used+Key_blocks_unused<>0, then Key_blocks_used/(Key_blocks_used+Key_blocks_unused), otherwise 0

6. Create disk storage temporary table ratio If Created_tmp_disk_tables+Created_tmp_tables<>0, then Created_tmp_disk_tables/(Created_tmp_disk_tables+Created_tmp_tables), otherwise 0

7. Connection usage rate: If max_connections<>0, then threads_connected/max_connections, otherwise 0

8. Open file ratio: if open_files_limit<>0, then open_files/open_files_limit, otherwise 0

9. Table cache usage If table_open_cache<>0, then open_tables/table_open_cache, otherwise 0

This is the end of this article about the example method of zabbix monitoring mysql. For more relevant zabbix monitoring mysql content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to monitor mysql using zabbix
  • Zabbix implements monitoring of multiple mysql processes
  • Detailed tutorial on how to monitor Nginx/Tomcat/MySQL using Zabbix
  • Detailed explanation of how Zabbix monitors the master-slave status of MySQL
  • How to monitor mysql using percona plugin in zabbix
  • Zabbix 2.4.5 comes with MySQL monitoring configuration tutorial
  • Basic tutorial on installing and configuring Zabbix to monitor MySQL

<<:  HTML fixed title column, title header table specific implementation code

>>:  Does the website's text still need to be designed?

Recommend

CentOS8 installation tutorial of jdk8 / java8 (recommended)

Preface At first, I wanted to use wget to downloa...

jQuery implements navigation bar effect with expansion animation

I designed and customized a navigation bar with a...

Let you understand the deep copy of js

Table of contents js deep copy Data storage metho...

Summary of various common join table query examples in MySQL

This article uses examples to describe various co...

Execution context and execution stack example explanation in JavaScript

JavaScript - Principles Series In daily developme...

HTML Tutorial: DOCTYPE Abbreviation

When writing HTML code, the first line should be ...

The meaning of the 5 types of spaces in HTML

HTML provides five space entities with different ...

SpringBoot integrates Activiti7 implementation code

After the official release of Activiti7, it has f...

Vue implements file upload and download functions

This article example shares the specific code of ...

Html to achieve dynamic display of color blocks report effect (example code)

Use HTML color blocks to dynamically display data...

In-depth understanding of the creation and implementation of servlets in tomcat

1. What is a servlet 1.1. Explain in official wor...

How to create Apache image using Dockerfile

Table of contents 1. Docker Image 2. Create an in...

The difference between HTML iframe and frameset_PowerNode Java Academy

Introduction 1.<iframe> tag: iframe is an i...