Monitoring MySQL with Percona monitoring for zabbix

Keywords: MySQL Zabbix PHP RPM

system requirements

The monitored hosts and MySQL monitored accounts, zabbix agent 2.0 or above (preferably the same as zabbix-server version), php, php-mysql (php version is not limited, after testing 5.3 is possible). Best version not too low), Percona Monitoring Plugins for Zabbix

Install zabbix agent

https://www.cnblogs.com/fishparadise/p/9067471.html

Install percona plugin

percona plugin requires php support. First install dependency packages:

yum install php php-mysql
wget https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.7/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.7-2.noarch.rpm

Or download rpm packages from percona

https://www.percona.com/downloads/percona-monitoring-plugins/LATEST/
rpm -ivh percona-zabbix-templates-1.1.7-2.noarch.rpm

Adding a dedicated account to the monitored mysql

mysql>CREATE USER 'zabbix_monitor'@'127.0.0.1' IDENTIFIED BY 'zabbix456';
mysql>GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT ON *.* TO 'zabbix_monitor'@'127.0.0.1';

Configure percona plugin

Modified to mysql account zabbix_monitor

vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'zabbix_monitor';
$mysql_pass = 'zabbix456';
$mysql_port = 3306;
vim /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
HOST=127.0.0.1

If you want to modify the time interval for percona plugin to collect data, modify 300 in the following code as the appropriate number in seconds.

elif [ -e $CACHEFILE ]; then
    # Check and run the script
    TIMEFLM=`stat -c %Y /tmp/$HOST-mysql_cacti_stats.txt`
    TIMENOW=`date +%s`
    if [ `expr $TIMENOW - $TIMEFLM` -gt 300 ]; then
        rm -f $CACHEFILE
        $CMD 2>&1 > /dev/null
    fi
else

Put the execution file percona wants to execute in the include directory of ZABBIX (zabbix calls this file). zabbix agent installs with rpm by default: / etc / ZABBIX / zabbix_agent D.D / directory, see the configuration file of zabbix agent.

cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/

Testing on client side

/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg

If a number is returned, the execution is proved to be successful.

Note: CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt" in vim get_mysql_stats_wrapper.sh will by default generate a temporary file under / tmp/, which will be deleted manually after testing! Otherwise, the program will not be able to delete this file, resulting in zabbix can not collect data!

If there is no data in the generated file manually tested by using root user login, use the following commands to test again:

/usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host 127.0.0.1 --items gg

The following error may be returned:

PHP MySQLi extension is not loaded

Install php-mysql

yum install php-mysql

Testing on the server side

(If it's a source installation)

/usr/local/zabbix/bin/zabbix_get -s 192.168.1.51 -k system.cpu.util[,idle]

If a number is returned, the execution is proved to be successful.

Configure the front-end page of zabbix-server

Installing percona plugin with RPM generates a template in / var/lib/zabbix/percona/templates, but the template zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml generated by percona-zabbix-templates-1.1.7-2.noarch.rpm is an old version for zabbix 2.0, which is not applicable.

Find a template for zabbix 3.0 online and log in
zabbix web: Configuration - > Templates - > Import in the upper right corner, select Screens, Maps, Images and import them.

The Itmes update data interval of the imported template can also be modified.

Posted by xshanelarsonx on Thu, 10 Jan 2019 13:54:09 -0800