aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools
diff options
context:
space:
mode:
authorViliam Luc <vluc@cisco.com>2022-04-04 11:27:44 +0200
committerPeter Mikus <pmikus@cisco.com>2022-04-19 07:51:37 +0000
commita717aee1ab89cef916caef845dca935dfc0f0cd1 (patch)
tree81d73be206811a77746abba2e0c6dc58ed5f123a /resources/tools
parent808613a09844882f121b173c2b6fccde3388a0ce (diff)
telemetry: convert openmetrics to readable output
Signed-off-by: Viliam Luc <vluc@cisco.com> Change-Id: I4b12f8e49a473ff54ca30d9ed3f02798136c6971
Diffstat (limited to 'resources/tools')
-rw-r--r--resources/tools/telemetry/bundle_bpf.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/resources/tools/telemetry/bundle_bpf.py b/resources/tools/telemetry/bundle_bpf.py
index b9baeab7ca..bf54db0bcd 100644
--- a/resources/tools/telemetry/bundle_bpf.py
+++ b/resources/tools/telemetry/bundle_bpf.py
@@ -90,6 +90,12 @@ class BundleBpf:
Fetch data by invoking API calls to BPF.
"""
self.serializer.create(metrics=self.metrics)
+
+ max_len = {"cpu": 3, "pid": 3, "name": 4, "value": 5}
+ text = ""
+ table_name = ""
+ item_list = []
+
for _, metric_list in self.metrics.items():
for metric in metric_list:
for (key, val) in self.obj.get_table(metric[u"name"]).items():
@@ -100,8 +106,43 @@ class BundleBpf:
for label in metric[u"labelnames"]:
labels[label] = getattr(key, label)
item[u"labels"] = labels
+ item[u'labels'][u'name'] = \
+ item[u'labels'][u'name'].decode(u'utf-8')
+ if item[u"labels"][u"name"] == u"python3":
+ continue
+ if len(str(item[u'labels'][u'cpu'])) > max_len["cpu"]:
+ max_len["cpu"]= len(str(item[u'labels'][u'cpu']))
+ if len(str(item[u'labels'][u'pid'])) > max_len[u"pid"]:
+ max_len[u"pid"] = len(str(item[u'labels'][u'pid']))
+ if len(str(item[u'labels'][u'name'])) > max_len[u"name"]:
+ max_len[u"name"] = len(str(item[u'labels'][u'name']))
+ if len(str(item[u'value'])) > max_len[u"value"]:
+ max_len[u"value"] = len(str(item[u'value']))
+
self.api_replies_list.append(item)
- getLogger(__name__).info(item)
+ item_list.append(item)
+
+ item_list = sorted(item_list, key=lambda x: x['labels']['cpu'])
+ item_list = sorted(item_list, key=lambda x: x['name'])
+
+ for it in item_list:
+ if table_name != it[u"name"]:
+ table_name = it[u"name"]
+ text += f"\n==={table_name}===\n" \
+ f"cpu {u' ' * (max_len[u'cpu'] - 3)} " \
+ f"pid {u' ' * (max_len[u'pid'] - 3)} " \
+ f"name {u' ' * (max_len[u'name'] - 4)} " \
+ f"value {u' ' * (max_len[u'value'] - 5)}\n"
+ text += (
+ f"""{str(it[u'labels'][u'cpu']) + u' ' *
+ (max_len[u"cpu"] - len(str(it[u'labels'][u'cpu'])))} """
+ f"""{str(it[u'labels'][u'pid']) + u' ' *
+ (max_len[u"pid"] - len(str(it[u'labels'][u'pid'])))} """
+ f"""{str(it[u'labels'][u'name']) + u' ' *
+ (max_len[u"name"] - len(str(it[u'labels'][u'name'])))} """
+ f"""{str(it[u'value']) + u' ' *
+ (max_len[u"value"] - len(str(it[u'value'])))}\n""")
+ getLogger(u"console_stdout").info(text)
def process_data(self):
"""