]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
src/pybind/mgr: handle json-pretty for perf stats 66492/head
authorNeeraj Pratap Singh <Neeraj.Pratap.Singh1@ibm.com>
Tue, 2 Dec 2025 12:20:52 +0000 (17:50 +0530)
committerNeeraj Pratap Singh <Neeraj.Pratap.Singh1@ibm.com>
Mon, 11 May 2026 10:08:01 +0000 (15:38 +0530)
Fixes: https://tracker.ceph.com/issues/74072
Signed-off-by: Neeraj Pratap Singh <Neeraj.Pratap.Singh1@ibm.com>
src/pybind/mgr/stats/fs/perf_stats.py
src/pybind/mgr/stats/module.py

index 7b97e42857a0f1104cdb018ef99296926f55e457..3c602d2e251ee8296f5972afde46f1f3c6868a49 100644 (file)
@@ -648,4 +648,4 @@ class FSPerfStats(object):
         with self.lock:
             user_query = self.register_query(filter_spec)
             result = self.generate_report(user_query)
-        return 0, json.dumps(result), ""
+        return result
index e3380ee414e97d4632d1a196364af8cc7239522e..119e370a1a6342c4c23ee16d72ee450f4f6b93bd 100644 (file)
@@ -4,6 +4,7 @@ performance stats for ceph filesystem (for now...)
 
 import json
 from typing import List, Dict
+from xml.dom.minidom import parseString
 
 from .cli import StatsCLICommand
 
@@ -11,6 +12,11 @@ from mgr_module import MgrModule, Option, NotifyType
 
 from .fs.perf_stats import FSPerfStats
 
+try:
+    from dicttoxml import dicttoxml # type: ignore[import-not-found] 
+except ImportError:
+    dicttoxml = None
+
 class Module(MgrModule):
     CLICommand = StatsCLICommand
     COMMANDS = [
@@ -40,5 +46,19 @@ class Module(MgrModule):
         prefix = cmd['prefix']
         # only supported command is `fs perf stats` right now
         if prefix.startswith('fs perf stats'):
-            return self.fs_perf_stats.get_perf_data(cmd)
+            result = self.fs_perf_stats.get_perf_data(cmd)
+            if 'format' in cmd:
+                if cmd['format'] == 'json-pretty':
+                    return 0, json.dumps(result, indent=2), ""
+                elif cmd['format'] == 'xml':
+                    if dicttoxml is None:
+                        raise ImportError("dicttoxml package required for xml")
+                    result = json.loads(json.dumps(result, default=str))
+                    return dicttoxml(result)
+                elif cmd['format'] == 'xml-pretty':
+                    if dicttoxml is None:
+                        raise ImportError("dicttoxml package required for xml")
+                    res_xml = parseString(dicttoxml(result))
+                    return res_xml.toprettyxml()
+            return 0, json.dumps(result), ""
         raise NotImplementedError(cmd['prefix'])