From 53cc27fde8ad8131cb00a9a3bd281ca2673241b3 Mon Sep 17 00:00:00 2001 From: Laura Flores Date: Thu, 30 Sep 2021 22:08:51 +0000 Subject: [PATCH] mgr/telemetry: add mempool stats to the perf report Adding mempool stats to the telemetry perf report for a deeper look at memory usage. Signed-off-by: Laura Flores --- src/pybind/mgr/telemetry/module.py | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/pybind/mgr/telemetry/module.py b/src/pybind/mgr/telemetry/module.py index 91596436a9d86..dd120ff9d0ae1 100644 --- a/src/pybind/mgr/telemetry/module.py +++ b/src/pybind/mgr/telemetry/module.py @@ -302,6 +302,42 @@ class Module(MgrModule): 'active_changed': sorted(list(active)), } + def get_mempool(self, mode: str = 'separated') -> Dict[str, dict]: + # Initialize result dict + result: Dict[str, dict] = defaultdict(lambda: defaultdict(int)) + + # Get list of osd ids from the metadata + osd_metadata = self.get('osd_metadata') + + # Grab output from the "osd.x dump_mempools" command + for osd_id in osd_metadata: + cmd_dict = { + 'prefix': 'dump_mempools', + 'id': str(osd_id), + 'format': 'json' + } + r, outb, outs = self.osd_command(cmd_dict) + if r != 0: + self.log.debug("Invalid command dictionary.") + continue + else: + try: + # This is where the mempool will land. + dump = json.loads(outb) + if mode == 'separated': + result["osd." + str(osd_id)] = dump['mempool']['by_pool'] + elif mode == 'aggregated': + for mem_type in dump['mempool']['by_pool']: + result[mem_type]['bytes'] += dump['mempool']['by_pool'][mem_type]['bytes'] + result[mem_type]['items'] += dump['mempool']['by_pool'][mem_type]['items'] + else: + self.log.debug("Incorrect mode specified in get_mempool") + except (json.decoder.JSONDecodeError, KeyError) as e: + self.log.debug("Error caught: {}".format(e)) + return {} + + return result + def get_stat_sum_per_pool(self) -> List[dict]: # Initialize 'result' list result: List[dict] = [] @@ -895,6 +931,9 @@ class Module(MgrModule): report['io_rate'] = self.get_io_rate() report['osd_perf_histograms'] = self.get_osd_histograms() + report['mempool_aggregated'] = self.get_mempool('aggregated') + report['mempool_separated'] = self.get_mempool('separated') + # NOTE: We do not include the 'device' channel in this report; it is # sent to a different endpoint. -- 2.39.5