【故障案例】一个Zabbix5.0 与Percona监控数据库的
2021-01-15 本文已影响0人
李导996
背景
- 早上有个,刚刚入职的小伙伴,找李导提问,说Zabbix监控MySQL要用percona
- 于是有了下面的故障
- 故障环境是: CentOS 7.6,Zabbix是5.0
- OK, Let's start .
流程
- zabbix环境是OK的,目前主要问题是
- 运行percona脚本的时候报错
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
ERROR: run the command manually to investigate the problem: /usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host 127.0.0.1 --items gg
- 但是直接执行里面的php脚本是不报错的
/usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host 127.0.0.1 --items gg
解决
- 定位问题,在脚本上面继续排查
- 问题为php生产的临时文件多个数字(随机)
- 脚本中并没有对应修改,
cat /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
#!/bin/sh
# The wrapper for Cacti PHP script.
# It runs the script every 5 min. and parses the cache file on each following run.
# Version: 1.1.8
#
# This program is part of Percona Monitoring Plugins
# License: GPL License (see COPYING)
# Copyright: 2018 Percona
# Authors: Roman Vynar
ITEM=$1
HOST=127.0.0.1
DIR=`dirname $0`
CMD="/usr/bin/php -q $DIR/ss_get_mysql_stats.php --host $HOST --items gg"
CACHEFILE="/tmp/${HOST}-mysql_cacti_stats.txt"
if [ "$ITEM" = "running-slave" ]; then
# Check for running slave
RES=`HOME=~zabbix mysql -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
if [ "$RES" = " Yes, Yes," ]; then
echo 1
else
echo 0
fi
exit
elif [ -e ${CACHEFILE}* ]; then
# Check and run the script
TIMEFLM=`stat -c %Y ${CACHEFILE}*`
TIMENOW=`date +%s`
if [ `expr $TIMENOW - $TIMEFLM` -gt 300 ]; then
rm -f $CACHEFILE
$CMD 2>&1 > /dev/null
fi
else
$CMD 2>&1 > /dev/null
fi
# Parse cache file
if [ -e ${CACHEFILE}* ]; then
cat ${CACHEFILE}* | sed 's/ /\n/g; s/-1/0/g'| grep $ITEM | awk -F: '{print $2}'
else
echo "ERROR: run the command manually to investigate the problem: $CMD"
fi
总结
- 平时多多练习下shell编程,对于这种故障难度不大.
- 有各种问题欢迎留言与交流