-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
71 lines (63 loc) · 2.61 KB
/
test.py
File metadata and controls
71 lines (63 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python
import sys
import urllib2
try:
import xml.etree.cElementTree as etree
except ImportError:
try:
import xml.etree.ElementTree as etree
except ImportError:
print 'python >= 2.5'
sys.exit()
SOLR_HOST = 'localhost'
SOLR_PORT = 8983
SOLR_URL = '/solr'
def get_cores():
return ['core']
url = 'http://%s:%s/%s/admin/cores?action=status' % (SOLR_HOST, SOLR_PORT, SOLR_URL)
f = urllib2.urlopen(url)
xml = etree.fromstring(f.read())
cores = [lst.attrib['name'].strip() for lst in xml.findall('./lst/lst')]
return cores
for core in get_cores():
url = 'http://%s:%s/%s/%s/admin/mbeans?stats=true' % (SOLR_HOST, SOLR_PORT, SOLR_URL, core)
#f = urllib2.urlopen(url)
f = open('stats.xml', 'r')
root = etree.fromstring(f.read())
# numDocs
core = root.findall('./response/lst/')
print core, dir(core)
for entry in core[0].xpath('entry'):
if entry[0].text.strip() == 'searcher':
stats = entry.xpath('stats')
for stat in stats[0]:
if stat.get("name") in ["numDocs"]:
print "docs.value", stat.text.strip()
core = root.xpath('/solr/solr-mbeans/CACHE')
stat_list = []
for entry in core[0].xpath('entry'):
if entry[0].text.strip() == 'documentCache' or \
entry[0].text.strip() == 'filterCache' or entry[0].text.strip() == 'queryResultCache':
description = entry.xpath('description')
match = re.findall(r'maxSize=([0-9]+)', description[0].text.strip())
maxsize = match[0]
stats = entry.xpath('stats')
for stat in stats[0]:
if stat.get('name') in ['lookups', 'hits', 'inserts', 'evictions', 'size']:
stat_list.append(stat.get('name') + '.value ' + stat.text.strip())
for i in stat_list:
print i
core = root.xpath('/solr/solr-mbeans/QUERYHANDLER')
for entry in core[0].xpath('entry'):
if entry[0].text.strip() == 'standard':
stats = entry.xpath('stats')
for stat in stats[0]:
if stat.get('name') == 'avgRequestsPerSecond':
print 'qps' + '.value', stat.text.strip()
if stat.get('name') == 'avgTimePerRequest':
print 'qtime' + '.value', stat.text.strip()
elif entry[0].text.strip() == '/update':
stats = entry.xpath('stats')
for stat in stats[0]:
if stat.get("name") == 'avgRequestsPerSecond':
print "ups.value", stat.text.strip()