From aaaef9146cd2a2c6511ea8a0f70612b84f476bd7 Mon Sep 17 00:00:00 2001 From: Boris Ranto Date: Mon, 29 Apr 2019 18:44:45 +0200 Subject: [PATCH] restful: Expose perf counters 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 --- qa/workunits/rest/test_mgr_rest_api.py | 5 +++-- src/pybind/mgr/restful/api/__init__.py | 2 ++ src/pybind/mgr/restful/api/perf.py | 27 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/pybind/mgr/restful/api/perf.py diff --git a/qa/workunits/rest/test_mgr_rest_api.py b/qa/workunits/rest/test_mgr_rest_api.py index 871f5709399..4d868e7a8d3 100755 --- a/qa/workunits/rest/test_mgr_rest_api.py +++ b/qa/workunits/rest/test_mgr_rest_api.py @@ -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: diff --git a/src/pybind/mgr/restful/api/__init__.py b/src/pybind/mgr/restful/api/__init__.py index ebf2bd1dfcd..a105dfe87f8 100644 --- a/src/pybind/mgr/restful/api/__init__.py +++ b/src/pybind/mgr/restful/api/__init__.py @@ -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 index 00000000000..4224599f669 --- /dev/null +++ b/src/pybind/mgr/restful/api/perf.py @@ -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 -- 2.47.3