1 #include <ObSensorGpu.h> 2 #include <ObSensorSystem.h> 5 #include <glibtop/cpu.h> 6 #include <spdlog/fmt/ostr.h> 7 #include <spdlog/sinks/stdout_color_sinks.h> 8 #include <spdlog/spdlog.h> 13 static shared_ptr<spdlog::logger> logger =
nullptr;
16 void help() { logger->info(
"obmon-sensor -o tcp://localhost:5000 -t 1000"); }
18 int main(
int argc,
char **argv) {
21 auto console = spdlog::stdout_color_mt(
"console");
22 logger = spdlog::get(
"console");
24 char *short_options = strdup(
"o:t:c:h");
25 struct option long_options[] = {{
"out", 1,
nullptr,
'o'},
26 {
"timeout", 1,
nullptr,
't'},
27 {
"cluster", 1,
nullptr,
'c'},
28 {
"help", 0,
nullptr,
'h'},
29 {
nullptr, 0,
nullptr, 0}};
31 string out =
">tcp://localhost:5000";
32 string cluster_name =
"wn";
34 string hostname = zsys_hostname();
38 getopt_long(argc, argv, short_options, long_options,
nullptr);
39 while (nextOption != -1) {
46 timeout = atoi(optarg);
49 cluster_name = optarg;
59 nextOption = getopt_long(argc, argv, short_options, long_options,
nullptr);
64 if (getenv(
"OBMON_LOG")) {
65 int rc = sscanf(getenv(
"OBMON_LOG"),
"%d", &debugLevel);
67 logger->error(
"salsa: OBMON_LOG is not a number: {}",
78 logger->info(
"Setting log level to '{}' ...",
79 spdlog::level::to_string_view(
80 static_cast<spdlog::level::level_enum>(6 - debugLevel)));
81 spdlog::set_level(static_cast<spdlog::level::level_enum>(6 - debugLevel));
84 zsock_t *pub = zsock_new_pub(out.data());
86 assert(zsock_resolve(pub) != pub);
87 assert(streq(zsock_type_str(pub),
"PUB"));
88 logger->info(
"Connected to {}", out);
94 s.update(static_cast<unsigned int>(timeout));
95 zclock_sleep(timeout);
96 while (!zsys_interrupted) {
97 s.update(static_cast<unsigned int>(timeout));
100 logger->debug(
"Sending : {}", json.data());
101 zmsg_t *msg = zmsg_new();
102 zmsg_addstr(msg,
"");
103 zmsg_addstrf(msg,
"%s", cluster_name.data());
104 zmsg_addstrf(msg,
"%s_%d", hostname.data(), getpid());
105 zmsg_addstrf(msg,
"%s", json.data());
106 zmsg_send(&msg, pub);
107 zclock_sleep(timeout);
System Obmon sensor class.