From ca0616d55929d903afa1f654d481524f1ebbfc6f Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Mon, 28 Feb 2022 13:58:25 +0100 Subject: [PATCH] exporter: socket magic Signed-off-by: Pere Diaz Bou --- src/ceph_exporter.cc | 12 ++++----- src/mgr/ActivePyModules.cc | 1 + src/mgr/DaemonMetricCollector.cc | 42 ++++++++++++++++++++++++++++++++ src/mgr/DaemonMetricCollector.h | 16 ++++++++++++ 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/ceph_exporter.cc b/src/ceph_exporter.cc index d19c2ae4b0570..a804033032f65 100644 --- a/src/ceph_exporter.cc +++ b/src/ceph_exporter.cc @@ -8,12 +8,12 @@ int main(int argc, char** argv) { // TODO: daemonize std::cout << "inside exporter" << std::endl; - std::map defaults = { - { "keyring", "$mgr_data/keyring" } - }; - auto args = argv_to_vec(argc, argv); - auto cct = global_init(&defaults, args, CEPH_ENTITY_TYPE_EXPORTER, - CODE_ENVIRONMENT_DAEMON, 0); + // std::map defaults = { + // { "keyring", "$mgr_data/keyring" } + // }; + // auto args = argv_to_vec(argc, argv); + // auto cct = global_init(&defaults, args, CEPH_ENTITY_TYPE_EXPORTER, + // CODE_ENVIRONMENT_DAEMON, 0); DaemonMetricCollector collector; collector.main(); } diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index 9ac03739595f6..58c3d9ee4d6f4 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -233,6 +233,7 @@ PyObject *ActivePyModules::get_python(const std::string &what) } else if (what.substr(0, 7) == "osd_map") { without_gil_t no_gil; cluster_state.with_osdmap([&](const OSDMap &osd_map){ + no_gil.acquire_gil(); if (what == "osd_map") { osd_map.dump(&f); } else if (what == "osd_map_tree") { diff --git a/src/mgr/DaemonMetricCollector.cc b/src/mgr/DaemonMetricCollector.cc index 8adcc39e551b9..4718f36d97545 100644 --- a/src/mgr/DaemonMetricCollector.cc +++ b/src/mgr/DaemonMetricCollector.cc @@ -1,7 +1,49 @@ #include "DaemonMetricCollector.h" +#include "common/admin_socket_client.h" + #include +#include +#include + +#include +#include +#include void DaemonMetricCollector::main() { std::cout << "metric" << std::endl; + while (1) { + update_sockets(); + } +} + +void update_sockets() { + for (const auto &entry : fs::recursive_directory_iterator(socketdir)) { + if (entry.path().extension() == ".asok") { + if (clients.find(entry.path()) == clients.end()) { + AdminSocketClient sock(entry.path()); + clients[entry.path()] = sock; + } + } + } +} + +void DaemonMetricCollector::send_request_per_client() { + AdminSocketClient mgr_sock_client("/var/run/ceph/whatever"); + std::string request("{\"prefix\":\"perf dump\"}"); + std::string path = "/run/" + for (const auto & entry : std::filesystem::directory_iterator(path)) { + if (clients.find(entry.path()) == clients.end()) { + AdminSocketClient sock(entry.path()); + clients[entry.path()] = sock; + } + } +} + +void DaemonMetricCollector::start_mgr_connection() { + AdminSocketClient mgr_sock_client("/var/run/ceph/whatever"); + std::string request("{\"prefix\":\"help\"}"); + std::string response; + mgr_sock_client.do_request(request, &response); + std::cout << response << std::endl; } diff --git a/src/mgr/DaemonMetricCollector.h b/src/mgr/DaemonMetricCollector.h index 93443f128f744..e51af8e739abd 100644 --- a/src/mgr/DaemonMetricCollector.h +++ b/src/mgr/DaemonMetricCollector.h @@ -1,7 +1,23 @@ #pragma once +#include "common/admin_socket_client.h" +#include +#include +#include + +#include +#include +#include class DaemonMetricCollector { public: int i; void main(); + +private: + // TODO: add clients + // check removed sockets + // list dir of sockets + std::map clients; + void update_sockets(); + void start_mgr_connection(); }; -- 2.39.5