A quick note with the python scipt I made to parse the Solr stats page and provide cache usage to Nagios.

It also return the number of documents indexed in SolR but without any check on it.

use -h option to get some help.

Copy this to your script folder of nagios and create a check like :
 

  1. define command{
  2.         command_name                    check_solr_cache
  3.         command_line                    $USER1$/check_solr_cache.py -H $HOSTADDRESS$ -p $ARG1$ -w $ARG2$ -c $ARG3$ -P $ARG4$
  4.         ;command_example                        !8080!30!10!/solr!
  5.         ;$ARG1$                         port – 8080
  6.         ;$ARG2$                         warning % – 30
  7.         ;$ARG3$                         critical % – 10
  8.         ;$ARG4$                         path to reach solr admin
  9. }

If your are using a clustered solR, change the path to the admin using the -P option. The latest solR for Typo3, for example, is installed under /solr/core_fr for French language.

It seems the script hereunder have some parts changed : ‘ ‘ ‘ are replaced by <<
Check that when you copy…

Again, this is a quick and dirty. No check is done on the stats URL response…

  1. #!/usr/bin/python
  2. #
  3.  »
  4. Project     :       Apache Solr Cache Check
  5. Version     :       0.1
  6. Author      :       prune
  7. Summary     :       This program is a nagios plugin that checks Apache Solr cache usage
  8. Dependency  :       Linux/nagios/Python-2.x
  9.  
  10. Usage :
  11. « « « `
  12. shell> python check_solr_cache.py
  13.  »
  14.  
  15. #———————–|
  16. # Import Python Modules |
  17. #———————–|
  18. import os, sys, urllib
  19. from xml.dom import minidom
  20. from optparse import OptionParser
  21.  
  22. #————————–|
  23. # Main Program Starts Here |
  24. #————————–|
  25. # Command Line Arguments Parser
  26. cmd_parser = OptionParser(version="%prog 0.1")
  27. cmd_parser.add_option("-H", "–host", type="string", action="store", dest="solr_server", help="SOLR Server IPADDRESS")
  28. cmd_parser.add_option("-p", "–port", type="string", action="store", dest="solr_server_port", help="SOLR Server port")
  29. cmd_parser.add_option("-w", "–warning", type="int", action="store", dest="warning_per", help="Exit with WARNING status if higher than the PERCENT of cache Usage", metavar="Warning Percentage")
  30. cmd_parser.add_option("-c", "–critical", type="int", action="store", dest="critical_per", help="Exit with CRITICAL status if higher than the PERCENT of cache Usage", metavar="Critical Percentage")
  31. cmd_parser.add_option("-P", "–path", type="string", action="store", dest="solr_server_path", help="SOLR Server path. Change it if using multicore SolR. Ex : /solr/core_fr", default="/solr")
  32. (cmd_options, cmd_args) = cmd_parser.parse_args()
  33. # Check the Command syntax
  34. if not (cmd_options.warning_per and cmd_options.critical_per and cmd_options.solr_server and cmd_options.solr_server_port):
  35.     cmd_parser.print_help()
  36.     sys.exit(3)
  37.  
  38. # set the locals
  39. STATE=0 # the nagios return code, 0=OK, 1=WARN, 2=CRIT, 3=unknown
  40. STATENAME=dict()
  41. STATENAME[0] = "OK"
  42. STATENAME[1] = "WARNING"
  43. STATENAME[2] = "CRITICAL"
  44. STATENAME[3] = "UNKNOWN"
  45. perfData =  » # performance data container
  46.  
  47. # Collect Solr Statistics Object
  48. class CollectStat:
  49.      »‘ Obejct to Collect the Statistics from the ‘n‘th Element of the XML Data’ »
  50.     def __init__(self):
  51.         self.stats = {}
  52.         solr_all_stat = minidom.parseString(urllib.urlopen(‘http://’ + cmd_options.solr_server + ‘:’ + cmd_options.solr_server_port + cmd_options.solr_server_path + ‘/admin/stats.jsp’).read())
  53.         entries = solr_all_stat.getElementsByTagName(‘entry’)
  54.         for stat in entries:
  55.                 name = stat.getElementsByTagName(‘name’)[0]
  56.                 if name.childNodes[0].data.strip() == ‘queryResultCache’ or name.childNodes[0].data.strip() == ‘documentCache’ or name.childNodes[0].data.strip() == ‘searcher’ :
  57.                         for statdata in stat.getElementsByTagName(‘stat’):
  58.                                 if statdata.getAttribute(‘name’) == ‘hitratio’:
  59.                                         self.stats[name.childNodes[0].data.strip()] = float(statdata.childNodes[0].data.strip())*100
  60.                                 elif statdata.getAttribute(‘name’) == ‘numDocs’:
  61.                                         self.stats[name.childNodes[0].data.strip()] = int(statdata.childNodes[0].data.strip())
  62.  
  63. # get the data
  64. solr_qps_stats = CollectStat()
  65.  
  66. # parse state and fill the perfdata
  67. for item in solr_qps_stats.stats:
  68.         perfData += "%s=%d%%;%d;%d " % (item, solr_qps_stats.stats[item],cmd_options.warning_per,cmd_options.critical_per)
  69.         if solr_qps_stats.stats[item] < cmd_options.critical_per and STATE < 2:
  70.                 STATE = 2
  71.         elif solr_qps_stats.stats[item] < cmd_options.warning_per and STATE < 1:
  72.                 STATE = 1
  73.  
  74. # return the state
  75. print "Solr Cache state is "+ STATENAME[STATE] +": " + perfData + " |"+perfData
  76. sys.exit(STATE)