Skip to content

Commit 1649195

Browse files
update hadoop_http.py, get more data (#451)
split the jmx dict, get all metrics in sub-dict or sub-list Fixes #393 #375 Co-authored-by: johnson7788 <[email protected]>
1 parent 11450ed commit 1649195

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

collectors/lib/hadoop_http.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
from collectors.lib.utils import is_numeric
2626

2727
try:
28+
# noinspection PyCompatibility
2829
from http.client import HTTPConnection
2930
except ImportError:
31+
# noinspection PyUnresolvedReferences,PyCompatibility
3032
from httplib import HTTPConnection
3133

3234

@@ -35,6 +37,20 @@
3537
"name"
3638
)
3739

40+
def recurse(key,value):
41+
if type(value) == dict:
42+
for k,v in value.items():
43+
newkey = '_'.join([key,k])
44+
for j in recurse(newkey,v):
45+
yield j
46+
elif type(value) == list:
47+
for i,x in enumerate(value):
48+
newi = '_'.join([key,str(i)])
49+
for j in recurse(newi,x):
50+
yield j
51+
else:
52+
yield (key,value)
53+
3854
class HadoopHttp(object):
3955
def __init__(self, service, daemon, host, port, uri="/jmx"):
4056
self.service = service
@@ -76,18 +92,19 @@ def poll(self):
7692
context = [c for c in context if c != self.service and c != self.daemon]
7793

7894
for key, value in bean.items():
79-
if key in EXCLUDED_KEYS:
80-
continue
81-
if not is_numeric(value):
82-
continue
83-
kept.append((context, key, value))
95+
for m, n in recurse(key, value):
96+
if m in EXCLUDED_KEYS:
97+
continue
98+
if not is_numeric(n):
99+
continue
100+
kept.append((context, m, n))
84101
return kept
85102

86103
def emit_metric(self, context, current_time, metric_name, value, tag_dict=None):
87104
if not tag_dict:
88105
print("%s.%s.%s.%s %d %d" % (self.service, self.daemon, ".".join(context), metric_name, current_time, float(value)))
89106
else:
90-
tag_string = " ".join([k + "=" + v for k, v in tag_dict.iteritems()])
107+
tag_string = " ".join([k + "=" + v for k, v in tag_dict.items()])
91108
print ("%s.%s.%s.%s %d %d %s" % \
92109
(self.service, self.daemon, ".".join(context), metric_name, current_time, float(value), tag_string))
93110
# flush to protect against subclassed collectors that output few metrics not having enough output to trigger

0 commit comments

Comments
 (0)