]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
restful: Expose perf counters 27885/head
authorBoris Ranto <branto@redhat.com>
Mon, 29 Apr 2019 16:44:45 +0000 (18:44 +0200)
committerBoris Ranto <branto@redhat.com>
Tue, 30 Apr 2019 11:30:14 +0000 (13:30 +0200)
We currently do not expose perf counters in the restful module but this
is a useful piece of information to be exposed by the restful module.

Since we already have a function to gather all the information about the
perf counters, we can make this easily accessible through the restful
API.

This also supports filtering by daemons through regexps.

Signed-off-by: Boris Ranto <branto@redhat.com>
qa/workunits/rest/test_mgr_rest_api.py
src/pybind/mgr/restful/api/__init__.py
src/pybind/mgr/restful/api/perf.py [new file with mode: 0644]

index 871f5709399b7197138a48800ba2b8ed42a9b80f..4d868e7a8d366dcbfa549ee40e308b44a286f844 100755 (executable)
@@ -72,8 +72,9 @@ screenplay = [
     ('get',    '/request?page=0', {}),
     ('delete', '/request', {}),
     ('get',    '/request', {}),
-    ('patch', '/pool/1', {'pg_num': 128}),
-    ('patch', '/pool/1', {'pgp_num': 128}),
+    ('patch',  '/pool/1', {'pg_num': 128}),
+    ('patch',  '/pool/1', {'pgp_num': 128}),
+    ('get',    '/perf?daemon=.*', {}),
 ]
 
 for method, endpoint, args in screenplay:
index ebf2bd1dfcde927be679ba41485651d71d4e77c7..a105dfe87f88ea588cc2b72f9ab07372b9cc8f2e 100644 (file)
@@ -7,6 +7,7 @@ from .doc import Doc
 from .mon import Mon
 from .osd import Osd
 from .pool import Pool
+from .perf import Perf
 from .request import Request
 from .server import Server
 
@@ -17,6 +18,7 @@ class Root(RestController):
     doc = Doc()
     mon = Mon()
     osd = Osd()
+    perf = Perf()
     pool = Pool()
     request = Request()
     server = Server()
diff --git a/src/pybind/mgr/restful/api/perf.py b/src/pybind/mgr/restful/api/perf.py
new file mode 100644 (file)
index 0000000..4224599
--- /dev/null
@@ -0,0 +1,27 @@
+from pecan import expose, request, response
+from pecan.rest import RestController
+
+from restful import context
+from restful.decorators import auth, lock, paginate
+
+import re
+
+class Perf(RestController):
+    @expose(template='json')
+    @paginate
+    @auth
+    def get(self, **kwargs):
+        """
+        List all the available performance counters
+
+        Options:
+         - 'daemon' -- filter by daemon, accepts Python regexp
+        """
+
+        counters = context.instance.get_all_perf_counters()
+
+        if 'daemon' in kwargs:
+            _re = re.compile(kwargs['daemon'])
+            counters = {k: v for k, v in counters.items() if _re.match(k)}
+
+        return counters