]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
exporter: socket magic
authorPere Diaz Bou <pdiazbou@redhat.com>
Mon, 28 Feb 2022 12:58:25 +0000 (13:58 +0100)
committerAvan Thakkar <athakkar@redhat.com>
Mon, 20 Jun 2022 18:20:46 +0000 (23:50 +0530)
Signed-off-by: Pere Diaz Bou <pdiazbou@redhat.com>
src/ceph_exporter.cc
src/mgr/ActivePyModules.cc
src/mgr/DaemonMetricCollector.cc
src/mgr/DaemonMetricCollector.h

index d19c2ae4b0570d44e5090a51f77a3435f84ae52b..a804033032f65dbe774797ae4beae5c256615185 100644 (file)
@@ -8,12 +8,12 @@
 int main(int argc, char** argv) {
   // TODO: daemonize
   std::cout << "inside exporter" << std::endl;
-  std::map<std::string,std::string> 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<std::string,std::string> 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();
 }
index 9ac03739595f6032d807fd037df097191a8dbf23..58c3d9ee4d6f4d9fc062150f645fa518313e9048 100644 (file)
@@ -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") {
index 8adcc39e551b905f14f4853cff4ec169a540ebd6..4718f36d9754537e7473ebbf9a7669c19f319128 100644 (file)
@@ -1,7 +1,49 @@
 #include "DaemonMetricCollector.h"
+#include "common/admin_socket_client.h"
+
 #include <iostream>
+#include <string>
+#include <filesystem>
+
 
+#include <iostream>
+#include <string>
+#include <filesystem>
 
 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;
 }
index 93443f128f74405f6efcfee24a89288c53c2aa5d..e51af8e739abd7950d89506278d7c858d8c1e02d 100644 (file)
@@ -1,7 +1,23 @@
 #pragma once
+#include "common/admin_socket_client.h"
+#include <string>
+#include <map>
+#include <vector>
+
+#include <string>
+#include <map>
+#include <vector>
 
 class DaemonMetricCollector {
  public:
   int i;
   void main();
+
+private:
+  // TODO: add clients
+  //       check removed sockets
+  //       list dir of sockets
+  std::map<std::string, AdminSocketClient> clients;
+  void update_sockets();
+  void start_mgr_connection();
 };