Hacking on GraphHopper - a Java road routing engine. Peter has posted 62 posts at DZone. You can read more from them at their website. View Full User Profile

Poor Man's Monitoring for Solr

11.26.2010
| 6341 views |
  • submit to reddit

As well as being the developer and PR agent for jetwick, sadly I'm also the admin ;-) . All in one... at once. Here is a minor snippet to get an alert email if your Solr index is either not available or contains too few entries. You'll  get a resolved mail if all is fine again.


cd /path/
FILE=bla.log
EMAILS="your@email.here"
SUBJECT="OK: jetwick"
STATUS=OK

CNT=`wget --http-user=user --http-password=password -T 10 -q "http://your-host.com/solr/select?q=&rows=1&wt=json" -O - | tr ',' '\n' |grep numFound|tr ':' ' '|awk '{print $3}'`
if [ "x$CNT" == x ] || [ "$CNT" -lt 500000 ]; then
SUBJECT="CRITICAL: check http://your-host.com/solr"
STATUS=CRITICAL
fi

PREV_STAT=`cat .status`

if [ "$STATUS" == "CRITICAL" ]; then
if [ "$PREV_STAT" == "OK" ]; then
cat $FILE | mail $EMAILS -a $FILE -s "$SUBJECT. doc count was only $CNT"
fi
echo CRITICAL > .status
else
if [ "$PREV_STAT" == "CRITICAL" ]; then
cat $FILE | mail $EMAILS -a $FILE -s "SOLVED: http://your-host.com/solr"
fi
echo OK > .status
fi

echo $STATUS > .status

add via this via crontab -e

*/2 * * * * /path/check-health.sh

If you look at the code there is one mini hack which is necessary if the solr index is down and the CNT is empty:

"x$CNT" == x

From http://karussell.wordpress.com/2010/11/25/poor-men-monitoring-for-solr/

Published at DZone with permission of its author, Peter Karussell.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Pranav Prakash replied on Tue, 2011/10/04 - 7:29am

One may also set up NAGIOS alerts to read log files from Solr to see for any errors.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.