]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/controllers/perf_counters.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / perf_counters.py
CommitLineData
11fdf7f2
TL
1# -*- coding: utf-8 -*-
2from __future__ import absolute_import
3
f67539c2
TL
4from typing import Any, Dict
5
11fdf7f2
TL
6import cherrypy
7
11fdf7f2
TL
8from .. import mgr
9from ..security import Scope
10from ..services.ceph_service import CephService
f67539c2
TL
11from . import ApiController, ControllerDoc, EndpointDoc, RESTController
12
13PERF_SCHEMA = {
14 "mon.a": ({
15 ".cache_bytes": ({
16 "description": (str, ""),
17 "nick": (str, ""),
18 "type": (int, ""),
19 "priority": (int, ""),
20 "units": (int, ""),
21 "value": (int, "")
22 }, ""),
23 }, "Service ID"),
24}
11fdf7f2
TL
25
26
27class PerfCounter(RESTController):
28 service_type = None # type: str
29
30 def get(self, service_id):
31 schema_dict = mgr.get_perf_schema(self.service_type, str(service_id))
32 try:
33 schema = schema_dict["{}.{}".format(self.service_type, service_id)]
34 except KeyError as e:
35 raise cherrypy.HTTPError(404, "{0} not found".format(e))
36 counters = []
37
38 for key, value in sorted(schema.items()):
39 counter = dict()
40 counter['name'] = str(key)
41 counter['description'] = value['description']
42 # pylint: disable=W0212
43 if mgr._stattype_to_str(value['type']) == 'counter':
44 counter['value'] = CephService.get_rate(
45 self.service_type, service_id, key)
46 counter['unit'] = mgr._unit_to_str(value['units'])
47 else:
48 counter['value'] = mgr.get_latest(
49 self.service_type, service_id, key)
50 counter['unit'] = ''
51 counters.append(counter)
52
53 return {
54 'service': {
55 'type': self.service_type,
56 'id': str(service_id)
57 },
58 'counters': counters
59 }
60
61
62@ApiController('perf_counters/mds', Scope.CEPHFS)
f67539c2 63@ControllerDoc("Mds Perf Counters Management API", "MdsPerfCounter")
11fdf7f2
TL
64class MdsPerfCounter(PerfCounter):
65 service_type = 'mds'
66
67
68@ApiController('perf_counters/mon', Scope.MONITOR)
f67539c2 69@ControllerDoc("Mon Perf Counters Management API", "MonPerfCounter")
11fdf7f2
TL
70class MonPerfCounter(PerfCounter):
71 service_type = 'mon'
72
73
74@ApiController('perf_counters/osd', Scope.OSD)
f67539c2 75@ControllerDoc("OSD Perf Counters Management API", "OsdPerfCounter")
11fdf7f2
TL
76class OsdPerfCounter(PerfCounter):
77 service_type = 'osd'
78
79
80@ApiController('perf_counters/rgw', Scope.RGW)
f67539c2 81@ControllerDoc("Rgw Perf Counters Management API", "RgwPerfCounter")
11fdf7f2
TL
82class RgwPerfCounter(PerfCounter):
83 service_type = 'rgw'
84
f67539c2
TL
85 def get(self, service_id: str) -> Dict[str, Any]:
86 svc_data = CephService.get_service_data_by_metadata_id(self.service_type, service_id)
87 service_map_id = svc_data['service_map_id']
88 schema_dict = mgr.get_perf_schema(self.service_type, service_map_id)
89 try:
90 schema = schema_dict["{}.{}".format(self.service_type, service_map_id)]
91 except KeyError as e:
92 raise cherrypy.HTTPError(404, "{0} not found".format(e))
93 counters = []
94
95 for key, value in sorted(schema.items()):
96 counter = dict()
97 counter['name'] = str(key)
98 counter['description'] = value['description']
99 # pylint: disable=W0212
100 if mgr._stattype_to_str(value['type']) == 'counter':
101 counter['value'] = CephService.get_rate(
102 self.service_type, service_map_id, key)
103 counter['unit'] = mgr._unit_to_str(value['units'])
104 else:
105 counter['value'] = mgr.get_latest(
106 self.service_type, service_map_id, key)
107 counter['unit'] = ''
108 counters.append(counter)
109
110 return {
111 'service': {
112 'type': self.service_type,
113 'id': svc_data['id']
114 },
115 'counters': counters
116 }
117
11fdf7f2
TL
118
119@ApiController('perf_counters/rbd-mirror', Scope.RBD_MIRRORING)
f67539c2 120@ControllerDoc("Rgw Mirroring Perf Counters Management API", "RgwMirrorPerfCounter")
11fdf7f2
TL
121class RbdMirrorPerfCounter(PerfCounter):
122 service_type = 'rbd-mirror'
123
124
125@ApiController('perf_counters/mgr', Scope.MANAGER)
f67539c2 126@ControllerDoc("Mgr Perf Counters Management API", "MgrPerfCounter")
11fdf7f2
TL
127class MgrPerfCounter(PerfCounter):
128 service_type = 'mgr'
129
130
81eedcae 131@ApiController('perf_counters/tcmu-runner', Scope.ISCSI)
f67539c2 132@ControllerDoc("Tcmu Runner Perf Counters Management API", "TcmuRunnerPerfCounter")
81eedcae
TL
133class TcmuRunnerPerfCounter(PerfCounter):
134 service_type = 'tcmu-runner'
135
136
11fdf7f2 137@ApiController('perf_counters')
f67539c2 138@ControllerDoc("Perf Counters Management API", "PerfCounters")
11fdf7f2 139class PerfCounters(RESTController):
f67539c2
TL
140 @EndpointDoc("Display Perf Counters",
141 responses={200: PERF_SCHEMA})
11fdf7f2
TL
142 def list(self):
143 return mgr.get_all_perf_counters()