From: Mykola Golub Date: Wed, 14 Nov 2018 07:33:01 +0000 (+0200) Subject: mgr: make dynamic osd perf counters accessible from modules X-Git-Tag: v14.1.0~843^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b8362d904a710c10ab72f15c78fdafc3ff21f020;p=ceph.git mgr: make dynamic osd perf counters accessible from modules Signed-off-by: Mykola Golub --- diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index ba281bddca09..595ac7d7e977 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -916,6 +916,48 @@ void ActivePyModules::remove_osd_perf_query(OSDPerfMetricQueryID query_id) } } +PyObject *ActivePyModules::get_osd_perf_counters(OSDPerfMetricQueryID query_id) +{ + std::map counters; + + int r = server.get_osd_perf_counters(query_id, &counters); + if (r < 0) { + dout(0) << "get_osd_perf_counters for query_id=" << query_id << " failed: " + << cpp_strerror(r) << dendl; + Py_RETURN_NONE; + } + + PyFormatter f; + + f.open_array_section("counters"); + for (auto &it : counters) { + auto &key = it.first; + auto &instance_counters = it.second; + f.open_object_section("i"); + f.open_array_section("k"); + for (auto &sub_key : key) { + f.open_array_section("s"); + for (size_t i = 0; i < sub_key.size(); i++) { + f.dump_string(stringify(i).c_str(), sub_key[i]); + } + f.close_section(); // s + } + f.close_section(); // k + f.open_array_section("c"); + for (auto &c : instance_counters) { + f.open_array_section("p"); + f.dump_unsigned("0", c.first); + f.dump_unsigned("1", c.second); + f.close_section(); // p + } + f.close_section(); // c + f.close_section(); // i + } + f.close_section(); // counters + + return f.get(); +} + void ActivePyModules::cluster_log(const std::string &channel, clog_type prio, const std::string &message) { diff --git a/src/mgr/ActivePyModules.h b/src/mgr/ActivePyModules.h index bccf821aee0b..03f0ee2d5fd0 100644 --- a/src/mgr/ActivePyModules.h +++ b/src/mgr/ActivePyModules.h @@ -94,6 +94,7 @@ public: OSDPerfMetricQueryID add_osd_perf_query(const OSDPerfMetricQuery &query); void remove_osd_perf_query(OSDPerfMetricQueryID query_id); + PyObject *get_osd_perf_counters(OSDPerfMetricQueryID query_id); bool get_store(const std::string &module_name, const std::string &key, std::string *val) const; diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index 0aee22318b4d..013d44756173 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -695,6 +695,18 @@ ceph_remove_osd_perf_query(BaseMgrModule *self, PyObject *args) Py_RETURN_NONE; } +static PyObject* +ceph_get_osd_perf_counters(BaseMgrModule *self, PyObject *args) +{ + OSDPerfMetricQueryID query_id; + if (!PyArg_ParseTuple(args, "i:ceph_get_osd_perf_counters", &query_id)) { + derr << "Invalid args!" << dendl; + return nullptr; + } + + return self->py_modules->get_osd_perf_counters(query_id); +} + PyMethodDef BaseMgrModule_methods[] = { {"_ceph_get", (PyCFunction)ceph_state_get, METH_VARARGS, "Get a cluster object"}, @@ -775,6 +787,9 @@ PyMethodDef BaseMgrModule_methods[] = { {"_ceph_remove_osd_perf_query", (PyCFunction)ceph_remove_osd_perf_query, METH_VARARGS, "Remove an osd perf query"}, + {"_ceph_get_osd_perf_counters", (PyCFunction)ceph_get_osd_perf_counters, + METH_VARARGS, "Get osd perf counters"}, + {NULL, NULL, 0, NULL} }; diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index e3c622d91361..4069715e8b79 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -2691,3 +2691,10 @@ int DaemonServer::remove_osd_perf_query(OSDPerfMetricQueryID query_id) { return osd_perf_metric_collector.remove_query(query_id); } + +int DaemonServer::get_osd_perf_counters( + OSDPerfMetricQueryID query_id, + std::map *counters) +{ + return osd_perf_metric_collector.get_counters(query_id, counters); +} diff --git a/src/mgr/DaemonServer.h b/src/mgr/DaemonServer.h index 6ccab441cf54..47020a884b4b 100644 --- a/src/mgr/DaemonServer.h +++ b/src/mgr/DaemonServer.h @@ -167,6 +167,8 @@ public: OSDPerfMetricQueryID add_osd_perf_query(const OSDPerfMetricQuery &query); int remove_osd_perf_query(OSDPerfMetricQueryID query_id); + int get_osd_perf_counters(OSDPerfMetricQueryID query_id, + std::map *c); virtual const char** get_tracked_conf_keys() const override; virtual void handle_conf_change(const ConfigProxy& conf,