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");
61 spdlog::set_level(spdlog::level::info);
65 spdlog::set_level(spdlog::level::debug);
69 spdlog::set_level(spdlog::level::trace);
81 spdlog::debug(
"======== Detected input arguments ========");
84 spdlog::debug(
"{} = {}", entry.first, entry.second);
88 spdlog::debug(
"======== Detected configuration ========");
91 spdlog::debug(
"{} = {}", entry.first, entry.second);
95 if (std::signal(SIGINT, interruptFunc) == SIG_ERR)
97 spdlog::critical(
"Can't set signal handler (SIGINT): {}",
getErrnoString(errno));
102 if (std::signal(SIGTERM, interruptFunc) == SIG_ERR)
104 spdlog::critical(
"Can't set signal handler (SIGTERM): {}",
getErrnoString(errno));
109 if (std::signal(SIGALRM, alarmFunc) == SIG_ERR)
111 spdlog::critical(
"Can't set signal handler (SIGALRM): {}",
getErrnoString(errno));
117 std::unique_ptr<Tracer> crashpadController(
nullptr);
118 vCheckFlag.emplace_back(
"Crashpad Handler", std::make_shared<std::atomic_flag>(
false));
119 crashpadController = std::make_unique<Tracer>(
121 config.
get(
"CRASHPAD_EXECUTABLE_PATH"), config.
get(
"CRASHPAD_REPORT_DIR"));
124 std::unique_ptr<PrometheusServer> mainPrometheusServer(
nullptr);
125 const std::string prometheusAddr = input.
getCmdOption(
"--enable-prometheus");
126 if (!prometheusAddr.empty())
130 mainPrometheusServer = std::make_unique<PrometheusServer>(prometheusAddr);
131 spdlog::info(
"Prometheus server start at {}", prometheusAddr);
133 catch (
const std::exception &e)
135 spdlog::error(
"Can't start Prometheus Server: {}", e.what());
141 std::unique_ptr<ProcessMetrics> selfMonitor(
nullptr);
142 vCheckFlag.emplace_back(
"Self Monitor", std::make_shared<std::atomic_flag>(
false));
143 if (mainPrometheusServer)
146 mainPrometheusServer->createNewRegistry());
150 std::unique_ptr<ZeroMQServer> zmqController(
nullptr);
151 vCheckFlag.emplace_back(
"ZeroMQ Server", std::make_shared<std::atomic_flag>(
false));
152 const std::string zeromqServerAddr = input.
getCmdOption(
"--enable-zeromq");
153 if (!zeromqServerAddr.empty())
157 zmqController = std::make_unique<ZeroMQServer>(
159 mainPrometheusServer ? mainPrometheusServer->createNewRegistry() :
nullptr);
161 zmqController->initialise();
163 catch (
const std::exception &e)
165 spdlog::error(
"Can't start ZeroMQ Server: {}", e.what());
171 std::shared_ptr<TelnetServer> telnetController(
nullptr);
172 vCheckFlag.emplace_back(
"Telnet Server", std::make_shared<std::atomic_flag>(
false));
173 const unsigned long telnetPort =
175 if (telnetPort > 0 && telnetPort < 65536)
179 telnetController = std::make_shared<TelnetServer>();
184 mainPrometheusServer ? mainPrometheusServer->createNewRegistry() :
nullptr);
186 catch (
const std::exception &e)
188 spdlog::error(
"Can't start Telnet Server: {}", e.what());
192 else if (telnetPort != 0)
194 spdlog::error(
"Invalid Telnet port: {}", telnetPort);
206 while (interruptFlag == 0)
208 std::this_thread::sleep_for(std::chrono::milliseconds(500));
219 curl_global_cleanup();
constexpr uintmax_t alarmInterval
int main(int argc, char **argv)