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 "")
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()
{
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;
}
--- /dev/null
+# -*- 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
#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>
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;
});
}
+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();
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;
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;
#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();
}
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();
}
#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>
});
}
-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;
#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);