3 minutes zabbix monitor configuration mysql

A small rise on the month mysql configuration cards for three days, because on the one hand are not familiar with, on the one hand I was yesterday at 18:00 configuration is completed, there is no data for a long time, they closed the desperate, last night I still entangled or not to continue to study, today opened it, have a data chart. The original mysql monitor, take a little time to take effect.

When you know the right way, I'm on another server configuration, in fact, only 3 minutes

  1. Mysql association template

Step: Configuration> Hosts> Click on the host> Templates

See Fig.

Dump failed
to re-upload
Cancel
Click to go to see the template description template

Requirements for template operation:
1.Install Zabbix agent and MySQL client.
2.Copy Template_DB_MySQL.conf into folder with Zabbix agent configuration (/etc/zabbix/zabbix_agentd.d/ by default). Don't forget restart zabbix-agent.
3.Create MySQL user for monitoring. For example:
CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY '<password>';
GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON . TO 'zbx_monitor'@'%';
For more information read the MYSQL documentation https://dev.mysql.com/doc/refman/8.0/en/grant.html , please.
4.Create .my.cnf in home directory of Zabbix agent for Linux (/var/lib/zabbix by default ) or my.cnf in c:\ for Windows. For example:
[client]
user=zbx_monitor
password=<password>
 
 
You can discuss this template or leave feedback on our forum https://www.zabbix.com/forum/zabbix-suggestions-and-feedback/384189-discussion-thread-for-official-zabbix-template-db-mysql
 
Template tooling version used: 0.35

  1. Set template mysql end
    Note: May not a small rise of the machine and / var / lib / zabbix can not find the template Template_DB_MySQL.conf, so I end up with is another userparameter_mysql.conf

1) mysql monitoring templates to see zabbix in, find / -name userparameter_mysql.conf

[root @ ~] # the Find / -name userparameter_mysql.conf
/backup/soft/zabbix-4.4.6/conf/zabbix_agentd/userparameter_mysql.conf
the first sentence of this document

template_db_mysql.conf of ZABBIX for the Created by # "Template DB MySQL" and of ZABBIX 4.2
2) copied to zabbix_agentd.conf.d / directory

-r /backup/soft/zabbix-4.4.6/conf/zabbix_agentd/userparameter_mysql.conf /usr/local/etc/zabbix_agentd.conf.d/ cp
3) test patterns are valid

zabbix_agentd -t mysql.ping -c /usr/local/etc/zabbix_agentd.conf.d/userparameter_mysql.conf

 
mysql.ping [T | mysqladmin: Connect to Server AT '-P' failed
error: 'Unknown the MySQL Host Server' -P '(2)'
. 4) to modify the template

cat /usr/local/etc/zabbix_agentd.conf.d/userparameter_mysql.conf

UserParameter = mysql.ping [*], mysqladmin -h "$ 1" -P "$ 2" ping
said -P do not know this parameter $ 1 $ 2 should be passed in from elsewhere parameters.

The following testing process tangled write, write final shape of the template

UserParameter=mysql.ping[], HOME=/etc/zabbix mysqladmin ping
 
UserParameter=mysql.get_status_variables[
],HOME=/etc/zabbix mysql -sNX -e "show global status"
UserParameter=mysql.version[],HOME=/etc/zabbix mysqladmin version
UserParameter=mysql.uptime,HOME=/etc/zabbix mysqladmin status | cut -f2 -d ":" | cut -f1 -d "T" | tr -d " "
 
UserParameter=mysql.db.discovery[
],HOME=/etc/zabbix mysql -sN -e "show databases"
UserParameter=mysql.dbsize[], HOME=/etc/zabbix mysql -sN -e "SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABL
ES WHERE TABLE_SCHEMA='$3'"
UserParameter=mysql.replication.discovery[
], HOME=/etc/zabbix mysql -sNX -e "show slave status"
UserParameter = mysql.slave_status [*], HOME = / etc / zabbix mysql -sNX -e "show slave status"
I copied this template and, in fact, only one more HOME = / etc / zabbix (native to believe template wording)

5) and do some of that .my.cnf

[MySQL]
the User = zbx_monitor
password = Javaer123456
[mysqladmin]
the User = zbx_monitor
password = Javaer123456
path /etc/zabbix/.my.cnf and above HOME = / etc / zabbix is not the same, right, HOME that means "Big Brother I came here. "

6) Restart zabbix_agentd

After this step, wait, wait 5 minutes, 10 minutes, do not worry.

7) Look data monitoring> Latest data

8) Look at the monitor icon> Graphics in

Dump failed
re-upload
Cancel
I think the process is repeated tangled userparameter_mysql.conf because a lot of things have not figured out.
END

===== ====== gorgeous dividing line
are reported below, the following number of logical records containing test can continue to read the configuration file zabbix bottom.

  1. How to confirm the configuration file can read a key

zabbix_agentd -t mysql.ping[*] -c /usr/local/etc/zabbix_agentd.conf.d/userparameter_mysql.conf

  1. How to confirm mysql functioning

mysqladmin -uzbx_monitor -p'Javaer123456' -hlocalhost ping

  1. How to confirm Zabbix_server agent can successfully read the key

zabbix_get -slocalhost -p 10050 -k mysql.ping

  1. A mandatory test parameters

zabbix_agentd -t mysql.ping [*] -c /usr/local/etc/zabbix_agentd.conf.d/userparameter_mysql.conf
forced into a written death, I will test mysql.ping a parameter

UserParameter=mysql.ping[*], mysqladmin -uzbx_monitor -p'Javaer123456' -hlocalhost ping
zabbix_agentd -t mysql.ping -c /usr/local/etc/zabbix_agentd.conf.d/userparameter_mysql.conf
mysql.ping [t|mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqld is alive]
查看mysqladmin是否正常

-uzbx_monitor -p'Javaer123456 #mysqladmin '-hlocalhost of ping
mysqladmin:. [Warning] A password ON the Using The Command Line interface CAN BE in the insecure
mysqld IS Alive
command line improvement, returns 1 or 0

mysqladmin -uzbx_monitor -p'Javaer123456' -hlocalhost ping|grep -c alive

I created a test .my.cnf in / etc / zabbix

UserParameter = mysql.ping, HOME = / etc / zabbix / mysqladmin ping | grep -c alive
this command "UserParameter" indicates that this is a user-defined script; after the "=" sign is the content of the script; "mysql.ping "Yes Key,", "the number will initiate a command to get Agent in Zabbix Server" is called when requested mysql.ping "the key, and return value to the Server.

Other parameters commented out

#UserParameter=mysql.ping[], mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.ping[
], mysqladmin -uzbx_monitor -p'Javaer123456' -hlocalhost ping
#UserParameter=mysql.get_status_variables[], mysql -h"$1" -P"$2" -sNX -e "show global status"
#UserParameter=mysql.version[
], mysqladmin -s -h"$1" -P"$2" version
#UserParameter=mysql.db.discovery[], mysql -h"$1" -P"$2" -sN -e "show databases"
#UserParameter=mysql.dbsize[
], mysql -h"$1" -P"$2" -sN -e "SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"
#UserParameter=mysql.replication.discovery[], mysql -h"$1" -P"$2" -sNX -e "show slave status"
#UserParameter=mysql.slave_status[
], mysql -h"$1" -P"$2" -sNX -e "show slave status"
重启动

Where the server-side reading test

zabbix_get -slocalhost -p 10050 -k mysql.ping
mysqld is alive

  1. Mysql test zabbix in other states extended-status

mysqladmin -uzbx_monitor -p'Javaer123456 '-hlocalhost extended-status
out of a pile of things

mysqladmin -uzbx_monitor -p'Javaer123456' -hlocalhost extended-status | grep -w "Threads_connected" | cut -d "|" -f 3
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
71

Testing this thing

UserParameter=mysql.status[*],mysqladmin -uzbx_monitor -p'Javaer123456' -hlocalhost extended-status | grep -w "Threads_connected" | cut -d "|" -f 3

zabbix_agentd -t mysql.status -c /usr/local/etc/zabbix_agentd.conf.d/userparameter_mysql.conf

mysql.status [t|mysqladmin: [Warning] Using a password on the command line interface can be insecure.
71]
zabbix_get -slocalhost -p 10050 -k mysql.status
mysqladmin -uzbx_monitor -p'Javaer123456' -hlocalhost extended-status | grep -w "Connections" | cut -d "|" -f 3
抄写个脚本给配置文件用

# / bin / the bash!
 
#Filename: chk_mysql.sh
 
MYSQL_SOCK = "/ var / lib / MySQL / mysql.sock"
mysql_user = 'zbx_monitor'
MYSQL_PASSWORD = 'Javaer123456'
MYSQL_HOST = 'localhost'
the MYSQL_PORT = '3306'
mysql_connect = "/ usr / bin / mysqladmin -u mysql_user -p $ $ $ MYSQL_HOST MYSQL_PASSWORD -H -S -P $ $ MYSQL_SOCK the MYSQL_PORT "
 
IF [$ # -ne. 1]; the then
echo" Please One arguement INPUT "
Fi
 
Case $. 1 in
 
The Uptime) # MySQL currently running statistical time after the start of this inquiry
the Result = ${MYSQL_Connect} status 2&gt;/dev/null | cut -d ":" -f 2 | cut -d " " -f 2
echo $ the Result
;;
 
Slow_queries) # View the current slow query the number of
the Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Slow_queries" | cut -d "|" -f 3
echo $ the Result
;;
 
Com_rollback) # number of rollback of
the Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Com_rollback" | cut -d "|" -f 3
echo $ the Result
;;
 
Questions)
result=${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Questions" | cut -d "|" -f 3
echo $result
;;
 
Com_commit)
Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Com_commit" | cut -d "|" -f 3
echo $ Result
;;
 
bytes_sent) # Bytes sent
Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Bytes_sent" | cut -d "|" -f 3
echo $ Result
;;
 
Bytes_received) # number of bytes accepted
Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Bytes_received" | cut -d "|" -f 3
echo $ Result
;;
 
Com_begin)
Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Com_begin" | cut -d "|" -f 3
echo $ Result
;;
 
Open_tables) # View the current number of tables open
the Result = ${MYSQL_Connect} status 2&gt;/dev/null | cut -d ":" -f 5 | cut -d " " -f 2
echo $ the Result
;;
 
Threads_connected) # View the number of connections that are currently open
the Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Threads_connected" | cut -d "|" -f 3
echo $ the Result
;;
 
Threads_cached) # View the number of threads in the thread cache
the Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Threads_cached" | cut -d "|" -f 3
echo $ the Result
;;
 
Threads_created ) # View the number of threads created to handle connections. If Threads_created large, you may want to increase the value thread_cache_size.
= the Result ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Threads_created" | cut -d "|" -f 3
echo the Result $
;;
 
Threads_running) # View active (non-sleep state) threads
result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Threads_running" | cut -d "|" -f 3
echo $ the Result
;;
 
Slow_launch_threads) # View the number of threads to create more than slow_launch_time seconds
result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Slow_launch_threads" | cut -d "|" -f 3
echo $ the Result
;;
 
Com_select) # View the number of execution of the select statement
result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Com_select" |cut -d "|" -f 3
the Result $ echo
;;
 
Com_insert) # View insert the number of execution of sentence
the Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Com_insert" |cut -d "|" -f 3
echo $ the Result
;;
 
Com_update) # View update statement execution number of
the Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Com_update" | cut -d "|" -f 3
echo $ the Result
;;
 
the number of execution Com_delete) # View delete statement
the Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Com_delete" | cut -d "|" -f 3
echo $ the Result
;;
 
connections) # View tries to connect to MySQL (number of connections regardless of whether the connection is successful) of
the Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Connections" | cut -d "|" -f 3
echo $ the Result
;;
 
Table_locks_immediate) # View the number of lock table immediately obtained
the Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Table_locks_immediate" | cut -d "|" -f 3
echo $ the Result
;;
 
Table_locks_waited) # Views locks table can not be obtained immediately. If the value is higher, and there are performance problems, you should first optimize the query, and then split the table or copy
the Result = ${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w "Table_locks_waited" | cut -d "|" -f 3
echo $ the 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
Usage: ./ chk.sh (Uptime | Com_update | Slow_queries | Com_select | Com_rollback | Questions | Com_insert | Com_delete | Com_commit | bytes_sent | Bytes_received | Com_begin)
file path

/usr/local/etc/zabbix_agentd.conf.d/chk.sh
script introduced in the configuration file

UserParameter = mysql.status [*], / usr / local / etc / zabbix_agentd.conf.d / chk.sh $ 1
to test the usefulness chk.sh

-k -p 10050 -slocalhost zabbix_get "mysql.status [Com_update]"
zabbix_get -slocalhost -p 10050 -k "mysql.threads_connected"
form a new version of the key corresponding to zabbix.
mysql.connections.rate

mysql.threads_connected

result=${MYSQL_Connect} extended-status 2&gt;/dev/null | grep -w “Threads_connected” | cut -d “|” -f 3
echo $result

A single configuration parameter mysql.threads_connected
UserParameter = mysql.threads_connected, mysqladmin -uzbx_monitor -p'Javaer123456 '-hlocalhost-Extended Status | grep -w "the Connections" | Cut -d "|" -f. 3

zabbix log

cat /tmp/zabbix_server.log

https://java-er.com/blog/zabbix-mysql-monitor/

Guess you like

Origin blog.51cto.com/yuexiaosheng/2481353