37int main(
int argc,
char **argv)
41 const MainLogger logger(config.
get(
"LOKI_ADDRESS"), config.
get(
"SENTRY_ADDRESS"));
44 if (curl_global_init(CURL_GLOBAL_DEFAULT) < 0)
46 spdlog::critical(
"Can't init curl");
53 spdlog::set_level(spdlog::level::info);
57 spdlog::set_level(spdlog::level::debug);
61 spdlog::set_level(spdlog::level::trace);
65 spdlog::debug(
"======== Detected input arguments ========");
68 spdlog::debug(
"{} = {}", entry.first, entry.second);
72 spdlog::debug(
"======== Detected configuration ========");
75 spdlog::debug(
"{} = {}", entry.first, entry.second);
79 if (std::signal(SIGINT, interruptFunc) == SIG_ERR)
81 spdlog::critical(
"Can't set signal handler (SIGINT): {}",
getErrnoString(errno));
86 if (std::signal(SIGTERM, interruptFunc) == SIG_ERR)
88 spdlog::critical(
"Can't set signal handler (SIGTERM): {}",
getErrnoString(errno));
93 if (std::signal(SIGALRM, alarmFunc) == SIG_ERR)
95 spdlog::critical(
"Can't set signal handler (SIGALRM): {}",
getErrnoString(errno));
101 std::unique_ptr<Tracer> crashpadController(
nullptr);
102 vCheckFlag.emplace_back(
"Crashpad Handler", std::make_shared<std::atomic_flag>(
false));
103 crashpadController = std::make_unique<Tracer>(
105 config.
get(
"CRASHPAD_EXECUTABLE_PATH"), config.
get(
"CRASHPAD_REPORT_DIR"));
108 std::unique_ptr<PrometheusServer> mainPrometheusServer(
nullptr);
109 const std::string prometheusAddr = input.
getCmdOption(
"--enable-prometheus");
110 if (!prometheusAddr.empty())
114 mainPrometheusServer = std::make_unique<PrometheusServer>(prometheusAddr);
115 spdlog::info(
"Prometheus server start at {}", prometheusAddr);
117 catch (
const std::exception &e)
119 spdlog::error(
"Can't start Prometheus Server: {}", e.what());
125 std::unique_ptr<ProcessMetrics> selfMonitor(
nullptr);
126 vCheckFlag.emplace_back(
"Self Monitor", std::make_shared<std::atomic_flag>(
false));
127 if (mainPrometheusServer)
130 mainPrometheusServer->createNewRegistry());
134 std::unique_ptr<ZeroMQServer> zmqController(
nullptr);
135 vCheckFlag.emplace_back(
"ZeroMQ Server", std::make_shared<std::atomic_flag>(
false));
136 const std::string zeromqServerAddr = input.
getCmdOption(
"--enable-zeromq");
137 if (!zeromqServerAddr.empty())
141 zmqController = std::make_unique<ZeroMQServer>(
143 mainPrometheusServer ? mainPrometheusServer->createNewRegistry() :
nullptr);
145 zmqController->initialise();
147 catch (
const std::exception &e)
149 spdlog::error(
"Can't start ZeroMQ Server: {}", e.what());
155 std::unique_ptr<TelnetServer> telnetController(
nullptr);
156 vCheckFlag.emplace_back(
"Telnet Server", std::make_shared<std::atomic_flag>(
false));
157 const unsigned long telnetPort =
159 if (telnetPort > 0 && telnetPort < 65536)
163 telnetController = std::make_unique<TelnetServer>();
168 mainPrometheusServer ? mainPrometheusServer->createNewRegistry() :
nullptr);
170 catch (
const std::exception &e)
172 spdlog::error(
"Can't start Telnet Server: {}", e.what());
176 else if (telnetPort != 0)
178 spdlog::error(
"Invalid Telnet port: {}", telnetPort);
190 while (interruptFlag == 0)
192 std::this_thread::sleep_for(std::chrono::milliseconds(500));
203 curl_global_cleanup();
constexpr uintmax_t alarmInterval
int main(int argc, char **argv)