1 #include <ObSensorSystem.h>
4 #include <glibtop/cpu.h>
5 #include <spdlog/fmt/ostr.h>
6 #include <spdlog/spdlog.h>
11 shared_ptr<spdlog::logger> logger =
nullptr;
13 void help() { logger->info(
"obmon-sensor -o tcp://localhost:5000 -t 1000"); }
15 int main(
int argc,
char **argv) {
18 auto console = spdlog::stdout_logger_mt(
"console");
19 logger = spdlog::get(
"console");
21 char *short_options = strdup(
"o:t:h");
22 struct option long_options[] = {{
"out", 1, NULL,
'o'},
23 {
"timeout", 1, NULL,
't'},
24 {
"help", 0, NULL,
'h'},
27 string out =
"@tcp://localhost:5000";
30 char nextOption = getopt_long(argc, argv, short_options, long_options, NULL);
31 while (nextOption != -1) {
38 timeout = atoi(optarg);
48 nextOption = getopt_long(argc, argv, short_options, long_options, NULL);
53 if (getenv(
"OBMON_LOG")) {
54 int rc = sscanf(getenv(
"OBMON_LOG"),
"%d", &debugLevel);
56 logger->error(
"salsa: OBMON_LOG is not a number: {}",
68 "Setting log level to '{}' ...",
69 spdlog::level::to_str((spdlog::level::level_enum)(6 - debugLevel)));
70 spdlog::set_level((spdlog::level::level_enum)(6 - debugLevel));
73 zsock_t *pub = zsock_new_pub(out.data());
75 assert(zsock_resolve(pub) != pub);
76 assert(streq(zsock_type_str(pub),
"PUB"));
84 zclock_sleep(timeout);
86 std::string hostname = zsys_hostname();
87 std::string cluster =
"ob_cluster";
90 while (!zsys_interrupted) {
94 logger->debug(
"Sending : {}", json.data());
95 zmsg_t *msg = zmsg_new();
97 zmsg_addstrf(msg,
"%s", cluster.data());
98 zmsg_addstrf(msg,
"%s_%d", hostname.data(), getpid());
99 zmsg_addstrf(msg,
"%s", json.data());
100 zmsg_send(&msg, pub);
103 zclock_sleep(timeout);
System Obmon sensor class.