I have a written a small script to monitor and sends email alert when there is a lots of Email in the Queue.
Hope, helps someone.
#!/bin/bash
echo " " ;
echo "=======================================================================================================" ;
date ;
for i in `cat /proc/vz/veinfo | awk '{print $1}'|egrep -v '^0$'`;
do
vmname=`/usr/sbin/vzctl exec2 $i hostname`
printf "$vmname " ;
#Check Exim MailQ
emailcnt=0
emailcnt=`/usr/sbin/vzctl exec2 $i /usr/sbin/exim -bpc 2> /tmp/emailcnt.log`
if [ $? -eq 0 ]
then
: # do nothing
else
echo "the return value is $?"
#Check Postfix MailQ
emailcnt=`/usr/sbin/vzctll exec2 $i /usr/sbin/postqueue -p > /tmp/emailcnt.log 2> /dev/null`
string=`cat /tmp/emailcnt.log`
if [[ $string == *"empty"* ]]; then emailcnt=1 ; fi
fi
echo "Email Count $emailcnt" ;
emailalert="yourmaailid here @gmail.com"
if [[ "$emailcnt" -ge 50 ]]
then
echo "Sending mail now" ;
echo -e "Email count on the Queue is $emailcnt : $vmname" | mail -s "Output of $0 on `hostname`" $emailalert
fi
done