From: Sebastian Wagner Date: Tue, 27 Mar 2018 13:06:18 +0000 (+0200) Subject: mgr/dashboard: Use `@ApiController` for PerfCounters X-Git-Tag: v13.1.0~468^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fdde9057b2eea9c43101f60a753aea76b7fce5f5;p=ceph.git mgr/dashboard: Use `@ApiController` for PerfCounters The next commit will require that all controllers have a `@ApiController` decorator. Signed-off-by: Sebastian Wagner --- diff --git a/src/pybind/mgr/dashboard/controllers/perf_counters.py b/src/pybind/mgr/dashboard/controllers/perf_counters.py index 5e6988af178d..8813fcb5624f 100644 --- a/src/pybind/mgr/dashboard/controllers/perf_counters.py +++ b/src/pybind/mgr/dashboard/controllers/perf_counters.py @@ -6,8 +6,7 @@ from ..tools import ApiController, AuthRequired, RESTController class PerfCounter(RESTController): - def __init__(self, service_type): - self._service_type = service_type + service_type = None # type: str def _get_rate(self, daemon_type, daemon_name, stat): data = mgr.get_counter(daemon_type, daemon_name, stat)[stat] @@ -22,8 +21,8 @@ class PerfCounter(RESTController): return 0 def get(self, service_id): - schema_dict = mgr.get_perf_schema(self._service_type, str(service_id)) - schema = schema_dict["{}.{}".format(self._service_type, service_id)] + schema_dict = mgr.get_perf_schema(self.service_type, str(service_id)) + schema = schema_dict["{}.{}".format(self.service_type, service_id)] counters = [] for key, value in sorted(schema.items()): @@ -33,34 +32,61 @@ class PerfCounter(RESTController): # pylint: disable=W0212 if mgr._stattype_to_str(value['type']) == 'counter': counter['value'] = self._get_rate( - self._service_type, service_id, key) + self.service_type, service_id, key) counter['unit'] = mgr._unit_to_str(value['units']) else: counter['value'] = self._get_latest( - self._service_type, service_id, key) + self.service_type, service_id, key) counter['unit'] = '' counters.append(counter) return { 'service': { - 'type': self._service_type, - 'id': service_id + 'type': self.service_type, + 'id': str(service_id) }, 'counters': counters } +@ApiController('perf_counters/mds') +@AuthRequired() +class MdsPerfCounter(PerfCounter): + service_type = 'mds' + + +@ApiController('perf_counters/mon') +@AuthRequired() +class MonPerfCounter(PerfCounter): + service_type = 'mon' + + +@ApiController('perf_counters/osd') +@AuthRequired() +class OsdPerfCounter(PerfCounter): + service_type = 'osd' + + +@ApiController('perf_counters/rgw') +@AuthRequired() +class RgwPerfCounter(PerfCounter): + service_type = 'rgw' + + +@ApiController('perf_counters/rbd-mirror') +@AuthRequired() +class RbdMirrorPerfCounter(PerfCounter): + service_type = 'rbd-mirror' + + +@ApiController('perf_counters/mgr') +@AuthRequired() +class MgrPerfCounter(PerfCounter): + service_type = 'mgr' + + @ApiController('perf_counters') @AuthRequired() class PerfCounters(RESTController): - def __init__(self): - self.mds = PerfCounter('mds') - self.mon = PerfCounter('mon') - self.osd = PerfCounter('osd') - self.rgw = PerfCounter('rgw') - self.rbd_mirror = PerfCounter('rbd-mirror') - self.mgr = PerfCounter('mgr') - def list(self): - counters = mgr.get_all_perf_counters() - return counters + return mgr.get_all_perf_counters()