How to monitor Solr performance under Tomcat.
I keep track of how many access and the performance, based on response time.
For this I have 2 scripts:
Here is the code:
#!/bin/bash
# script to check how many erros in the current hour
# Only works if your log file is in the format /var/log/tomcat6/access_log${tday2}.log
# Felipe Ferreira June 2012
# updated May/2015
dia=`date +%d -d "1 hour ago"`
mes=`date +%b -d "1 hour ago"`
mes2=`date +%m -d "1 hour ago"`
ano=`date +%Y -d "1 hour ago"`
hora=`date +%H -d "1 hour ago"`
tday="${dia}/${mes}/${ano}:${hora}"
tday2="${ano}-${mes2}-${dia}"
if [ $# -lt 2 ]
then
echo "No arguments supplied"
echo "Usage: $0 "
echo "Example: $0 200 5 10"
exit 1
fi
key=$1
warn=$2
crit=$3
log="/var/log/tomcat6/access_log${tday2}.log"
if [ ! -f $log ]; then
echo "OK - File $log not found!"
exit 0
fi
log_short=`echo $log|awk -F"/" '{ print $NF}'`
CMD="tail -n 300000 $log |grep '$tday'|grep -c ' ${key} '"
#echo $CMD
c=`eval $CMD`
if [ -z "$c" ]; then
c=0
fi
if [ "$c" -ge "$crit" ]; then
echo "CRITICAL - Existem $c $key no $log_short as $hora horas|count=$c"
exit 2
elif [ "$c" -ge "$warn" ]; then
echo "WARNING - Existem $c $key no $log_short as $hora horas|count=$c"
exit 1
else
echo "OK - Existem $c $key no $log_short as $hora horas|count=$c"
exit 0
fi
here is the code for the average calculation script:
Here is the code:
#!/bin/bash
# script to check Solr performance based on Qtime of last hour
# Felipe Ferreira Set 2013
dia=`date +%d -d "1 hour ago"`
mes=`date +%m -d "1 hour ago"`
ano=`date +%Y -d "1 hour ago"`
tday="${ano}-${mes}-${dia}"
#Numero de chamadas a verificar
nc=1000
log="/var/log/tomcat6/access_log${tday}.log"
if [ "$2" == "" ]
then
echo -e "\n Syntax: $0 \nex.: $0 50 900 \n O script retoran a media do tempo das $nc ultimas chamads\n"
exit 3
fi
warn=$1
crit=$2
CMD_SUM="tail -n $nc $log | grep ' 200 ' | awk '{ print \$( NF - 3) }' | awk '{sum+=\$1} END { print sum }'"
#echo $CMD_SUM
sum=`eval $CMD_SUM`
#echo $sum
media=`expr $sum / $nc`
MSG=" Tempo meido de $media ms. nas ultimas $nc chamadas ao Solr|media=$media"
#echo $MSG
if [ $media -ge $crit ]; then
echo "CRITICAL - $MSG"
exit 2
elif [ $media -ge $warn ]; then
echo "WARNING - $MSG"
exit 1
else
echo "OK - $MSG"
exit 0
fi
