summaryrefslogtreecommitdiffstats
path: root/src/exporter/ceph_exporter.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/exporter/ceph_exporter.cc')
-rw-r--r--src/exporter/ceph_exporter.cc58
1 files changed, 47 insertions, 11 deletions
diff --git a/src/exporter/ceph_exporter.cc b/src/exporter/ceph_exporter.cc
index 2e2c16bb085..2232851c094 100644
--- a/src/exporter/ceph_exporter.cc
+++ b/src/exporter/ceph_exporter.cc
@@ -1,33 +1,47 @@
#include "common/ceph_argparse.h"
#include "common/config.h"
-#include "exporter/DaemonMetricCollector.h"
-#include "exporter/web_server.h"
+#include "common/debug.h"
#include "global/global_init.h"
#include "global/global_context.h"
-
+#include "global/signal_handler.h"
+#include "exporter/DaemonMetricCollector.h"
+#include "exporter/web_server.h"
#include <boost/thread/thread.hpp>
#include <iostream>
#include <map>
#include <string>
+#include <atomic>
+#include <chrono>
+#include <thread>
#define dout_context g_ceph_context
+#define dout_subsys ceph_subsys_ceph_exporter
+
+DaemonMetricCollector &collector = collector_instance();
+
+static void handle_signal(int signum)
+{
+ ceph_assert(signum == SIGINT || signum == SIGTERM);
+ derr << "*** Got signal " << sig_str(signum) << " ***" << dendl;
+ // Finish the DaemonMetricCollector
+ collector.shutdown();
+}
static void usage() {
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"
- " --cert-file: Path to the certificate file to use https\n"
- " --key-file: Path to the certificate key file to use https\n"
+ " --sock-dir: The path to Ceph daemon sockets (*.asok)\n"
+ " --addrs: Host IP address on which the exporter is to listen\n"
+ " --port: TCP Port on which the exporter is to listen. Default is 9926\n"
+ " --cert-file: Path to the certificate file when using HTTPS\n"
+ " --key-file: Path to the certificate key file when using HTTPS\n"
" --prio-limit: Only perf counters greater than or equal to prio-limit are fetched. Default: 5\n"
- " --stats-period: Time to wait before sending requests again to exporter server (seconds). Default: 5s"
+ " --stats-period: Interval between daemon scrapes (seconds). Default: 5s"
<< std::endl;
generic_server_usage();
}
int main(int argc, char **argv) {
-
auto args = argv_to_vec(argc, argv);
if (args.empty()) {
std::cerr << argv[0] << ": -h or --help for usage" << std::endl;
@@ -64,8 +78,30 @@ int main(int argc, char **argv) {
}
common_init_finish(g_ceph_context);
+ // Register signal handlers
+ init_async_signal_handler();
+ register_async_signal_handler(SIGHUP, sighup_handler);
+ register_async_signal_handler_oneshot(SIGINT, handle_signal);
+ register_async_signal_handler_oneshot(SIGTERM, handle_signal);
+
+ // Start the web server thread
boost::thread server_thread(web_server_thread_entrypoint);
- DaemonMetricCollector &collector = collector_instance();
+
+ // Start the DaemonMetricCollector
collector.main();
+
+ // Interrupted. Time to terminate
+ unregister_async_signal_handler(SIGHUP, sighup_handler);
+ unregister_async_signal_handler(SIGINT, handle_signal);
+ unregister_async_signal_handler(SIGTERM, handle_signal);
+ shutdown_async_signal_handler();
+
+ // Stop the web server thread by interrupting it
+ stop_web_server();
+ server_thread.interrupt(); // Interrupt the web server thread
server_thread.join();
+
+ dout(1) << "Ceph exporter stopped" << dendl;
+
+ return 0;
}