-
Notifications
You must be signed in to change notification settings - Fork 16
/
hadoop.jobtracker.py
executable file
·68 lines (57 loc) · 1.91 KB
/
hadoop.jobtracker.py
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
#!/usr/bin/env python
import sys
import requests
import json
import socket
names = ['*']
excludes = ['blacklistednodesinfojson',
'configversion',
'name',
'hostname',
'modelertype',
'version',
'queueinfojson',
'alivenodesinfojson',
'hostname',
'health',
'last_seen',
'slots',
'summaryjson']
metrics = {}
node_data = {}
sum_data = {}
for n in names:
URL = 'http://%s:50030/jmx?qry=hadoop:service=JobTracker,name=%s' % (socket.getfqdn(), n)
try:
resp = requests.get(URL, timeout=60).json()['beans']
# Get all of the top level metrics
for i in range(len(resp)):
for k, v in resp[i].iteritems():
if k.lower() not in excludes:
metrics[k] = v
# Parse info about individual nodes
for i in json.loads(resp[0]['AliveNodesInfoJson']):
for k, v in i.iteritems():
node_name = i.values()[0].split('.')[0]
if k.lower() == 'slots':
for a,b in v.iteritems():
node_data[node_name + '.' + a] = b
elif k.lower() not in excludes:
node_data[node_name + '.' + k] = v
metrics.update(node_data)
# Parse summary data
summary = json.loads(resp[0]['SummaryJson'])
for k, v in summary.iteritems():
if k.lower() == 'slots':
for a,b in v.iteritems():
sum_data['total_' + a] = b
elif k.lower() not in excludes:
sum_data['total_' + k] = v
metrics.update(sum_data)
except:
print "Plugin Failed!"
sys.exit(2)
output = "OK | "
for k, v in metrics.iteritems():
output += str(k).lower() + '=' + str(v).lower() + ';;;; '
print output