]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
expoter: add configs
authorAvan Thakkar <athakkar@redhat.com>
Mon, 9 May 2022 12:12:44 +0000 (17:42 +0530)
committerAvan Thakkar <athakkar@redhat.com>
Mon, 20 Jun 2022 18:24:54 +0000 (23:54 +0530)
Signed-off-by: Avan Thakkar <athakkar@redhat.com>
src/common/options/CMakeLists.txt
src/common/options/build_options.cc
src/common/options/ceph-exporter.yaml.in [new file with mode: 0644]
src/exporter/DaemonMetricCollector.cc
src/exporter/DaemonMetricCollector.h
src/exporter/ceph_exporter.cc
src/exporter/http_server.cc
src/exporter/http_server.h

index d2104a0dad2671bb74c88147950f91206699e7b1..da24c673f6b374045d651be22aedee08a200a00b 100644 (file)
@@ -93,6 +93,7 @@ add_options(osd)
 add_options(rbd)
 add_options(rbd-mirror)
 add_options(immutable-object-cache)
+add_options(ceph-exporter)
 
 # if set to empty string, system default luarocks package location (if exist) will be used
 set(rgw_luarocks_location "")
index 001fac90287c04d6b1332a79464e38f0914036c4..867fc2efd7e1ba2ca80f6a376f664ca8a5ef4c56 100644 (file)
@@ -18,6 +18,7 @@ std::vector<Option> get_immutable_object_cache_options();
 std::vector<Option> get_mds_options();
 std::vector<Option> get_mds_client_options();
 std::vector<Option> get_cephfs_mirror_options();
+std::vector<Option> get_ceph_exporter_options();
 
 std::vector<Option> build_options()
 {
@@ -46,6 +47,7 @@ std::vector<Option> build_options()
   ingest(get_mds_options(), "mds");
   ingest(get_mds_client_options(), "mds_client");
   ingest(get_cephfs_mirror_options(), "cephfs-mirror");
+  ingest(get_ceph_exporter_options(), "ceph-exporter");
 
   return result;
 }
diff --git a/src/common/options/ceph-exporter.yaml.in b/src/common/options/ceph-exporter.yaml.in
new file mode 100644 (file)
index 0000000..ac6a6ee
--- /dev/null
@@ -0,0 +1,39 @@
+# -*- mode: YAML -*-
+---
+
+options:
+- name: sock_dir
+  type: str
+  level: advanced
+  desc: The path to ceph daemons socket files dir
+  default: /var/run/ceph/
+  services:
+  - ceph-exporter
+- name: exporter_addrs
+  type: str
+  level: advanced
+  desc: Host ip address where exporter is deployed
+  default: 127.0.0.1
+  services:
+  - ceph-exporter
+- name: exporter_port
+  type: int
+  level: advanced
+  desc: Port to deploy exporter on. Default is 9926
+  default: 9926
+  services:
+  - ceph-exporter
+- name: exporter_prio_limit
+  type: int
+  level: advanced
+  desc: Only perf counters greater than or equal to exporter_prio_limit are fetched
+  default: 10
+  services:
+  - ceph-exporter
+- name: exporter_stats_period
+  type: int
+  level: advanced
+  desc: Time to wait before sending requests again to exporter server (seconds)
+  default: 5
+  services:
+  - ceph-exporter
\ No newline at end of file
index 5881e51f282b6241ed03e1597e24c3d17de4e0e4..bc922da75f663fceadd08139746fb42fa2f41f56 100644 (file)
@@ -1,6 +1,8 @@
 #include "DaemonMetricCollector.h"
 #include "common/admin_socket_client.h"
 #include "common/perf_counters.h"
+#include "global/global_init.h"
+#include "global/global_context.h"
 #include "include/common_fwd.h"
 
 #include <boost/json/src.hpp>
@@ -14,8 +16,6 @@ using json_object = boost::json::object;
 using json_value = boost::json::value;
 using json_array = boost::json::array;
 
-const char *DaemonMetricCollector::SOCKETDIR = "/var/run/ceph/";
-
 void DaemonMetricCollector::request_loop(boost::asio::steady_timer &timer) {
   timer.async_wait([&](const boost::system::error_code &e) {
     std::cerr << e << std::endl;
@@ -26,12 +26,14 @@ void DaemonMetricCollector::request_loop(boost::asio::steady_timer &timer) {
   });
 }
 
+void DaemonMetricCollector::set_sock_dir(std::string sock_dir) {
+  SOCKETDIR = sock_dir;
+}
+
 void DaemonMetricCollector::main() {
   // TODO: let's do 5 for now and expose this to change in the future
-  stats_period = 5;
+  stats_period = g_conf().get_val<int64_t>("exporter_stats_period");;
   boost::asio::io_service io;
-  // boost::asio::deadline_timer timer(io,
-  //                                   boost::posix_time::seconds(stats_period));
   boost::asio::steady_timer timer{io, std::chrono::seconds(stats_period)};
   request_loop(timer);
   io.run();
@@ -91,8 +93,9 @@ void DaemonMetricCollector::dump_asok_metrics() {
       for (auto &perf_counter : perf_group_object) {
         std::string perf_name = perf_counter.key().to_string();
         json_object perf_info = perf_counter.value().as_object();
+        int plimit = g_conf().get_val<int64_t>("exporter_prio_limit");
         if (perf_info["priority"].as_int64() <
-            PerfCountersBuilder::PRIO_USEFUL) {
+            plimit) {
           continue;
         }
         std::string name = "ceph_" + perf_group + "_" + perf_name;
index 8258d510b724964ef8d878eb29d07e7ef02ea1e7..9d138ee81074df15dc8c72255c7df1b10e3a1a01 100644 (file)
@@ -15,8 +15,9 @@
 class DaemonMetricCollector {
 public:
   void main();
+  void set_sock_dir(std::string sock_path);
   std::string get_metrics();
-  static const char *SOCKETDIR;
+  std::string SOCKETDIR = "/var/run/ceph/";
 
 private:
   std::map<std::string, AdminSocketClient> clients;
index 4cf64ef4e7d674fee02c6575a23060eb9c7a9eca..2dd0d2fa8f7e600977c448b09ab4f3e4e904f5d9 100644 (file)
@@ -1,20 +1,25 @@
 #include "common/ceph_argparse.h"
+#include "common/config.h"
 #include "exporter/DaemonMetricCollector.h"
 #include "exporter/http_server.h"
+#include "global/global_init.h"
+#include "global/global_context.h"
+
 #include <boost/thread/thread.hpp>
 #include <iostream>
 #include <map>
 #include <string>
 
+#define dout_context g_ceph_context
+
 static void usage() {
-  std::cout << "usage: ceph-exporter --cert cert.pem --key cert.key "
-               "--tls_options no[flags]\n"
-            << "--cert: TLS/SSL certificate in pem format\n"
-            << "--key: TLS/SSL key in pem format\n"
-            << "--tls_options: colon separated options for tls and ssl.\n"
-            << "\tExample -> "
-               "default_workarounds:no_compression:no_sslv2:no_sslv3:no_tlsv1:"
-               "no_tlsv1_1:no_tlsv1_2:single_dh_use\n"
+  std::cout << "usage: ceph-exporter [options]\n"
+            << "options:\n"
+               "  --sock-dir: The path to ceph daemons socket files dir\n"
+               "  --addrs: Host ip address where exporter is deployed\n"
+               "  --port: Port to deploy exporter on. Default is 9926\n"
+               "  --prio-limit: Only perf counters greater than or equal to exporter_prio_limit are fetched\n"
+               "  --stats-period: Time to wait before sending requests again to exporter server (seconds)"
             << std::endl;
   generic_server_usage();
 }
@@ -30,25 +35,37 @@ int main(int argc, char **argv) {
     usage();
     exit(0);
   }
-  std::string val, cert_path, key_path, tls_options;
+
+  auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
+                         CODE_ENVIRONMENT_DAEMON, 0);
+  std::string val, sock_dir, exporter_addrs, exporter_port, exporter_prio_limit;
   for (auto i = args.begin(); i != args.end();) {
-    if (ceph_argparse_witharg(args, i, &val, "--cert", (char *)NULL)) {
-      cert_path = val;
-    } else if (ceph_argparse_witharg(args, i, &val, "--key", (char *)NULL)) {
-      key_path = val;
-    } else if (ceph_argparse_witharg(args, i, &val, "--tls_options",
-                                     (char *)NULL)) {
-      tls_options = val;
-    } else if (ceph_argparse_flag(args, i, "--help", (char *)NULL) ||
-               ceph_argparse_flag(args, i, "-h", (char *)NULL)) {
-      usage();
-      exit(0);
+    if (ceph_argparse_double_dash(args, i)) {
+      break;
+    } else if (ceph_argparse_witharg(args, i, &val, "--sock-dir", (char *)NULL)) {
+      sock_dir = val;
+      cct->_conf.set_val("sock_dir", val);
+    } else if (ceph_argparse_witharg(args, i, &val, "--addrs", (char *)NULL)) {
+      exporter_addrs = val;
+      cct->_conf.set_val("exporter_addrs", val);
+    } else if (ceph_argparse_witharg(args, i, &val, "--port", (char *)NULL)) {
+      exporter_port = val;
+      cct->_conf.set_val("exporter_port", val);
+    } else if (ceph_argparse_witharg(args, i, &val, "--prio-limit", (char *)NULL)) {
+      exporter_prio_limit = val;
+      cct->_conf.set_val("exporter_prio_limit", val);
+    } else if (ceph_argparse_witharg(args, i, &val, "--stats-period", (char *)NULL)) {
+      exporter_prio_limit = val;
+      cct->_conf.set_val("exporter_stats_period", val);
+    } else {
+      ++i;
     }
   }
+  common_init_finish(g_ceph_context);
 
-  boost::thread server_thread(http_server_thread_entrypoint, cert_path,
-                              key_path, tls_options);
+  boost::thread server_thread(http_server_thread_entrypoint, exporter_addrs, exporter_port);
   DaemonMetricCollector &collector = collector_instance();
+  collector.set_sock_dir(sock_dir);
   collector.main();
   server_thread.join();
 }
index 5cd153e33c1c1e8451e1245f7ca223059436475e..2f746401a62603a3fb17a00dd0beeeb3b723578c 100644 (file)
@@ -1,5 +1,7 @@
 #include "http_server.h"
 #include "common/hostname.h"
+#include "global/global_init.h"
+#include "global/global_context.h"
 #include "exporter/DaemonMetricCollector.h"
 
 #include <boost/asio.hpp>
@@ -134,32 +136,18 @@ void http_server(tcp::acceptor &acceptor, tcp::socket &socket) {
   });
 }
 
-std::string dns_lookup(std::string hostname) {
-  boost::asio::io_service io_service;
-  boost::asio::ip::tcp::resolver resolver(io_service);
-  boost::asio::ip::tcp::resolver::query query(hostname, "9926");
-  boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query);
-  boost::asio::ip::tcp::endpoint endpoint = iter->endpoint();
-  std::string ip_address = endpoint.address().to_string();
-
-  return ip_address;
-}
-
-void http_server_thread_entrypoint(std::string cert_path, std::string key_path,
-                                   std::string tls_options) {
+void http_server_thread_entrypoint(std::string exporter_addrs, std::string exporter_port) {
   try {
-    std::string hostname = ceph_get_short_hostname();
-
-    std::string ip_address = dns_lookup(hostname);
-    auto const address = net::ip::make_address(ip_address);
-    unsigned short port = 9926;
+    exporter_addrs = !exporter_addrs.empty() ? exporter_addrs : g_conf().get_val<std::string>("exporter_addrs");
+    auto const address = net::ip::make_address(exporter_addrs);
+    unsigned short port = g_conf().get_val<int64_t>("exporter_port");
 
     net::io_context ioc{1};
 
     tcp::acceptor acceptor{ioc, {address, port}};
     tcp::socket socket{ioc};
     http_server(acceptor, socket);
-    std::cout << "Http server started" << std::endl;
+    std::cout << "Http server running on " << std::quoted(exporter_addrs + ":" + exporter_port) << std::endl;
     ioc.run();
   } catch (std::exception const &e) {
     std::cerr << "Error: " << e.what() << std::endl;
index 368932ae03a54908b46f493f86ef9b89e99379b5..4aa2c9b81a773bdfbc0e2f78e9cfddf960210e89 100644 (file)
@@ -2,4 +2,4 @@
 
 #include <string>
 
-void http_server_thread_entrypoint(std::string cert_path, std::string key_path, std::string tls_options);
+void http_server_thread_entrypoint(std::string exporter_addrs, std::string exporter_port);