|
25 | 25 | from collectors.lib.utils import is_numeric |
26 | 26 |
|
27 | 27 | try: |
| 28 | + # noinspection PyCompatibility |
28 | 29 | from http.client import HTTPConnection |
29 | 30 | except ImportError: |
| 31 | + # noinspection PyUnresolvedReferences,PyCompatibility |
30 | 32 | from httplib import HTTPConnection |
31 | 33 |
|
32 | 34 |
|
|
35 | 37 | "name" |
36 | 38 | ) |
37 | 39 |
|
| 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 | + |
38 | 54 | class HadoopHttp(object): |
39 | 55 | def __init__(self, service, daemon, host, port, uri="/jmx"): |
40 | 56 | self.service = service |
@@ -76,18 +92,19 @@ def poll(self): |
76 | 92 | context = [c for c in context if c != self.service and c != self.daemon] |
77 | 93 |
|
78 | 94 | 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)) |
84 | 101 | return kept |
85 | 102 |
|
86 | 103 | def emit_metric(self, context, current_time, metric_name, value, tag_dict=None): |
87 | 104 | if not tag_dict: |
88 | 105 | print("%s.%s.%s.%s %d %d" % (self.service, self.daemon, ".".join(context), metric_name, current_time, float(value))) |
89 | 106 | 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()]) |
91 | 108 | print ("%s.%s.%s.%s %d %d %s" % \ |
92 | 109 | (self.service, self.daemon, ".".join(context), metric_name, current_time, float(value), tag_string)) |
93 | 110 | # flush to protect against subclassed collectors that output few metrics not having enough output to trigger |
|
0 commit comments