监控长时间进行的 mysql 查询

监控长时间进行的 mysql 查询

是否有任何插件或可能性可以使用 nagios MySQL 查询进行检查,该查询的运行时间超过 1 小时?这样我就能收到警报并可以进行管理吗?

我使用这个代码,但我不知道如何将其转移到 nagios 插件中

#!/bin/bash
trigger=20
hostname=server.name
activeQcount=`mysql -e "show full processlist;" | egrep -v "leechprotect|root|Time" | awk -v T=$trigger '{ if ( $6 > T ) print $0}' | wc -l`
if [ $activeQcount -gt 0 ]
then
echo "=====================================================================================" > /tmp/MySQLcheckquery
echo "= MySQL Query Check recognized running script longer than 60mins" >> /tmp/MySQLcheckquery
echo "=====================================================================================" >> /tmp/MySQLcheckquery
date >> /tmp/MySQLcheckquery
echo "" >> /tmp/MySQLcheckquery
mysql -e "show full processlist;" >> /tmp/MySQLcheckquery
echo "=====================================================================================">> /tmp/MySQLcheckquery
cat /tmp/MySQLMon | awk -v T=$trigger '{ if ( $6 > T ) print $0}' | \
mail -s"MySQL Query Check recognized running script longer than $trigger seconds on $hostname"  $trigger seconds on "[email protected]" -- -r "rob$
fi

相关内容