Révision e900462d
Initial version
| plugins/other/solr | ||
|---|---|---|
| 1 |
#!/usr/bin/python |
|
| 2 |
import sys, os |
|
| 3 |
import urllib2 |
|
| 4 |
try: |
|
| 5 |
from xml.etree import cElementTree as ET |
|
| 6 |
except ImportError: |
|
| 7 |
try: |
|
| 8 |
import cElementTree as ET |
|
| 9 |
except ImportError: |
|
| 10 |
sys.exit(1) |
|
| 11 |
|
|
| 12 |
SOLR_PORT=8389 |
|
| 13 |
SOLR_HOST="localhost" |
|
| 14 |
# Parameters: |
|
| 15 |
# |
|
| 16 |
# config (required) |
|
| 17 |
# autoconf (optional - used by munin-config) |
|
| 18 |
# |
|
| 19 |
# Magic markers (Used by munin-config and some installation scripts. |
|
| 20 |
# Optional): |
|
| 21 |
# author: Tarjei Huse (tarjei - at - kraken.no) |
|
| 22 |
# |
|
| 23 |
#%# family=auto |
|
| 24 |
#%# capabilities=autoconf |
|
| 25 |
|
|
| 26 |
def parseArgs(): |
|
| 27 |
"Parses the name of the file " |
|
| 28 |
parts = sys.argv[0].split("_")
|
|
| 29 |
params = {
|
|
| 30 |
'cores' : [core1], |
|
| 31 |
'valueName' : "avgTimePerRequest" |
|
| 32 |
} |
|
| 33 |
if len(parts) == 1: |
|
| 34 |
return params |
|
| 35 |
|
|
| 36 |
params['valueName'] = parts[1] |
|
| 37 |
if len(parts) < 3: |
|
| 38 |
return params |
|
| 39 |
params['cores'] = parts[2:] |
|
| 40 |
return params |
|
| 41 |
|
|
| 42 |
def printGraphdef(name, label, info, _min, _max, _type): |
|
| 43 |
|
|
| 44 |
print "%s.label %s" % (name, label) |
|
| 45 |
# print "%s.info %s" % (name, info) |
|
| 46 |
print "%s.max %d" % (name, _max) |
|
| 47 |
print "%s.min %d" % (name, _min) |
|
| 48 |
print "%s.type %s" % (name, _type) |
|
| 49 |
def fetchUrl(core): |
|
| 50 |
if ("URL" in os.environ):
|
|
| 51 |
URL=os.environ['URL'] |
|
| 52 |
else: |
|
| 53 |
URL="http://%s:%d/%s/admin/stats.jsp" |
|
| 54 |
|
|
| 55 |
response = urllib2.urlopen(URL % (SOLR_HOST, SOLR_PORT, core)) |
|
| 56 |
return parse(response) |
|
| 57 |
|
|
| 58 |
def parse(response): |
|
| 59 |
root = ET.parse(response) |
|
| 60 |
queues = root.findall("/solr-info/QUERYHANDLER/entry")
|
|
| 61 |
return queues |
|
| 62 |
|
|
| 63 |
def fetchFile(): |
|
| 64 |
f = open("/tmp/stats.jsp.html")
|
|
| 65 |
return parse(f) |
|
| 66 |
|
|
| 67 |
def getEntry(entries, entryName): |
|
| 68 |
for entry in entries: |
|
| 69 |
name = entry.findtext("name").strip()
|
|
| 70 |
if (name != entryName): |
|
| 71 |
continue |
|
| 72 |
return entry.find("stats")
|
|
| 73 |
|
|
| 74 |
def getValue(entry, valueName): |
|
| 75 |
for stat in entry: |
|
| 76 |
if stat.get('name') == valueName:
|
|
| 77 |
return stat.text |
|
| 78 |
#print "Could not find %s for entry" % valueName |
|
| 79 |
return 0 |
|
| 80 |
|
|
| 81 |
if len(sys.argv) > 1: |
|
| 82 |
if sys.argv[1]== "autoconf": |
|
| 83 |
# check connection |
|
| 84 |
sys.exit(0) |
|
| 85 |
elif sys.argv[1] == "config": |
|
| 86 |
params = parseArgs() |
|
| 87 |
|
|
| 88 |
print 'graph_title Solr %s' % params['valueName'] |
|
| 89 |
print 'graph_args -l 0 ' |
|
| 90 |
print 'graph_vlabel Size %s' % params['valueName'] |
|
| 91 |
print 'graph_category Solr' |
|
| 92 |
print 'graph_info Info for cores: %s' % ( ",".join(params['cores'])) |
|
| 93 |
|
|
| 94 |
for core in params['cores']: |
|
| 95 |
#print core, params['valueName'] |
|
| 96 |
print "%s-%s.label %s-%s" % (core, params['valueName'], params['valueName'], core) |
|
| 97 |
print "%s-%s.type GAUGE" % (core, params['valueName']) |
|
| 98 |
print "%s-%s.min 0" % (core, params['valueName']) |
|
| 99 |
sys.exit(0) |
|
| 100 |
|
|
| 101 |
|
|
| 102 |
params = parseArgs() |
|
| 103 |
for core in params['cores']: |
|
| 104 |
#print core, params['valueName'] |
|
| 105 |
queues = fetchUrl(core) |
|
| 106 |
searcher = getEntry(queues, "org.apache.solr.handler.StandardRequestHandler") |
|
| 107 |
value = getValue(searcher, params['valueName']).strip() |
|
| 108 |
print "%s-%s.value %s" % (core, params['valueName'], value) |
|
| 109 |
|
|
| 110 |
|
|
| 111 |
sys.exit(0) |
|
Formats disponibles : Unified diff