]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
exporter: fix metrics names + scrape all exporter endpoints in cephadm
authorAvan Thakkar <athakkar@redhat.com>
Mon, 18 Apr 2022 17:07:02 +0000 (22:37 +0530)
committerAvan Thakkar <athakkar@redhat.com>
Mon, 20 Jun 2022 18:20:47 +0000 (23:50 +0530)
Signed-off-by: Avan Thakkar <athakkar@redhat.com>
src/exporter/DaemonMetricCollector.cc
src/pybind/mgr/cephadm/services/monitoring.py

index b5b023a448f24ca4b511356df420fb4e403a9adb..962723415931e97dd424788dea3a56220bd9d5d6 100644 (file)
@@ -64,6 +64,11 @@ std::string quote(std::string value) {
        return "\"" + value + "\"";
 }
 
+bool Ishyphen(char ch)
+{
+    return ch == '-' ;
+}
+
 void DaemonMetricCollector::send_requests() {
   std::string result;
   for(auto client : clients) {
@@ -71,21 +76,13 @@ void DaemonMetricCollector::send_requests() {
     std::string daemon_name = client.first;
     std::string request("{\"prefix\":\"perf dump\"}");
     std::string response;
-    try {
-        sock_client.do_request(request, &response);
-      }
-    catch (const std::exception& e) {
-        std::cout << "culprit: " << daemon_name << std::endl;
-        std::cerr << "Mission abort!!: " << e.what() << std::endl;
-      }
+    sock_client.do_request(request, &response);
     if (response.size() > 0) {
-      std::cout << "wow: " << daemon_name << std::endl;
       json_object dump = boost::json::parse(response).as_object();
       request = "{\"prefix\":\"perf schema\"}";
       response = "";
       sock_client.do_request(request, &response);
       json_object schema = boost::json::parse(response).as_object();  
-      std::cout << "nice: " << schema << std::endl;
       for (auto perf : schema) {
         std::string perf_group = perf.key().to_string();
         json_object perf_group_object = perf.value().as_object();
@@ -100,13 +97,15 @@ void DaemonMetricCollector::send_requests() {
           std::string description = boost_string_to_std(perf_info["description"].as_string());
           std::stringstream ss;
           std::string name = "ceph_" + perf_group + "_" + perf_name;
+          std::replace_if(name.begin(), name.end(), Ishyphen, '_');
 
           std::string labels;
           // Labels
           // FIXME: test this, based on mgr_module perfpath_to_path_labels
           if (daemon_name.find("rgw") != std::string::npos) {
-            std::cout << "rgw: " << daemon_name << std::endl;
-            labels = std::string("instance_id=") + quote(daemon_name.substr(4, std::string::npos));
+            std::string tmp = daemon_name.substr(16, std::string::npos);
+            std::string::size_type pos = tmp.find('.');
+            labels = std::string("instance_id=") + quote("rgw." + tmp.substr(0, pos));
           } else {
             labels = "ceph_daemon=" + quote(daemon_name);
             if (daemon_name.find("rbd-mirror") != std::string::npos) {
@@ -151,12 +150,10 @@ void DaemonMetricCollector::send_requests() {
 void DaemonMetricCollector::update_sockets() {
   for (const auto & entry : std::filesystem::recursive_directory_iterator(socketdir)) {
     if (entry.path().extension() == ".asok") {
-      // std::cout << entry.path() << std::endl;
       std::string daemon_socket_name = entry.path().filename().string();
       // remove .asok
       std::string daemon_name = daemon_socket_name.substr(0, daemon_socket_name.size() - 5);
       if (clients.find(daemon_name) == clients.end() && !(daemon_name.find("mgr") != std::string::npos)) {
-        std::cout << "pathhh: " << entry.path().string() << std::endl;
         AdminSocketClient sock(entry.path().string());
         clients.insert({daemon_name, std::move(sock)});
       }
index 2b93674a01ce17c12fabd8e6529126c624b5057b..d68d25e5e0cca9dc8212b98a57222e6b8c5da404 100644 (file)
@@ -287,10 +287,8 @@ class PrometheusService(CephadmService):
             # append the brackets when building the final scrape endpoint
             if '[' in p_result.netloc and ']' in p_result.netloc:
                 mgr_scrape_list.append(f"[{p_result.hostname}]:{port}")
-                mgr_scrape_list.append(f"[{p_result.hostname}]:{exporter_port}")
             else:
                 mgr_scrape_list.append(f"{p_result.hostname}:{port}")
-                mgr_scrape_list.append(f"{p_result.hostname}:{exporter_port}")
 
         # scan all mgrs to generate deps and to get standbys too.
         # assume that they are all on the same port as the active mgr.
@@ -317,6 +315,12 @@ class PrometheusService(CephadmService):
                 'hostname': dd.hostname,
                 'url': build_url(host=addr, port=port).lstrip('/')
             })
+        
+        # scrape ceph exporters
+        for dd in self.mgr.cache.get_daemons_by_service('exporter'):
+            assert dd.hostname is not None
+            addr = self._inventory_get_fqdn(dd.hostname)
+            mgr_scrape_list.append(build_url(host=addr, port=exporter_port).lstrip('/'))
 
         # scrape alert managers
         alertmgr_targets = []