Skip to content

Commit

Permalink
update hadoop_http.py, get more data
Browse files Browse the repository at this point in the history
split the jmx dict, get all metrics in sub-dict or sub-list

Fixes #393 #375
  • Loading branch information
johnson7788 authored and johann8384 committed Oct 28, 2020
1 parent e86209c commit ce95f51
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions collectors/lib/hadoop_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
from collectors.lib.utils import is_numeric

try:
# noinspection PyCompatibility
from http.client import HTTPConnection
except ImportError:
# noinspection PyUnresolvedReferences,PyCompatibility
from httplib import HTTPConnection


Expand All @@ -35,6 +37,20 @@
"name"
)

def recurse(key,value):
if type(value) == dict:
for k,v in value.items():
newkey = '_'.join([key,k])
for j in recurse(newkey,v):
yield j
elif type(value) == list:
for i,x in enumerate(value):
newi = '_'.join([key,str(i)])
for j in recurse(newi,x):
yield j
else:
yield (key,value)

class HadoopHttp(object):
def __init__(self, service, daemon, host, port, uri="/jmx"):
self.service = service
Expand Down Expand Up @@ -76,18 +92,19 @@ def poll(self):
context = [c for c in context if c != self.service and c != self.daemon]

for key, value in bean.items():
if key in EXCLUDED_KEYS:
continue
if not is_numeric(value):
continue
kept.append((context, key, value))
for m, n in recurse(key, value):
if m in EXCLUDED_KEYS:
continue
if not is_numeric(n):
continue
kept.append((context, m, n))
return kept

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

0 comments on commit ce95f51

Please sign in to comment.