37int main(
int argc,
char **argv)
45 std::invalid_argument(std::format(
"{} {}",
"Failed to load configuration:", config.
getLastError()));
48 const MainLogger logger(config.
get(
"LOKI_ADDRESS"), config.
get(
"SENTRY_ADDRESS"));
51 if (curl_global_init(CURL_GLOBAL_DEFAULT) < 0)
53 spdlog::critical(
"Can't init curl");
68 spdlog::set_level(spdlog::level::info);
72 spdlog::set_level(spdlog::level::debug);
76 spdlog::set_level(spdlog::level::trace);
88 spdlog::debug(
"======== Detected input arguments ========");
91 spdlog::debug(
"{} = {}", entry.first, entry.second);
95 spdlog::debug(
"======== Detected configuration ========");
98 spdlog::debug(
"{} = {}", entry.first, entry.second);
102 if (std::signal(SIGINT, interruptFunc) == SIG_ERR)
104 spdlog::critical(
"Can't set signal handler (SIGINT): {}",
getErrnoString(errno));
109 if (std::signal(SIGTERM, interruptFunc) == SIG_ERR)
111 spdlog::critical(
"Can't set signal handler (SIGTERM): {}",
getErrnoString(errno));
116 if (std::signal(SIGALRM, alarmFunc) == SIG_ERR)
118 spdlog::critical(
"Can't set signal handler (SIGALRM): {}",
getErrnoString(errno));
124 std::unique_ptr<Tracer> crashpadController(
nullptr);
125 vCheckFlag.emplace_back(
"Crashpad Handler", std::make_shared<std::atomic_flag>(
false));
126 crashpadController = std::make_unique<Tracer>(
128 config.
get(
"CRASHPAD_EXECUTABLE_PATH"), config.
get(
"CRASHPAD_REPORT_DIR"));
131 std::unique_ptr<PrometheusServer> mainPrometheusServer(
nullptr);
132 const std::string prometheusAddr = input.
getCmdOption(
"--enable-prometheus");
133 if (!prometheusAddr.empty())
137 mainPrometheusServer = std::make_unique<PrometheusServer>(prometheusAddr);
138 spdlog::info(
"Prometheus server start at {}", prometheusAddr);
140 catch (
const std::exception &e)
142 spdlog::error(
"Can't start Prometheus Server: {}", e.what());
148 std::unique_ptr<ProcessMetrics> selfMonitor(
nullptr);
149 vCheckFlag.emplace_back(
"Self Monitor", std::make_shared<std::atomic_flag>(
false));
150 if (mainPrometheusServer)
153 mainPrometheusServer->createNewRegistry());
157 std::unique_ptr<ZeroMQServer> zmqController(
nullptr);
158 vCheckFlag.emplace_back(
"ZeroMQ Server", std::make_shared<std::atomic_flag>(
false));
159 const std::string zeromqServerAddr = input.
getCmdOption(
"--enable-zeromq");
160 if (!zeromqServerAddr.empty())
164 zmqController = std::make_unique<ZeroMQServer>(
166 mainPrometheusServer ? mainPrometheusServer->createNewRegistry() :
nullptr);
168 zmqController->initialise();
170 catch (
const std::exception &e)
172 spdlog::error(
"Can't start ZeroMQ Server: {}", e.what());
178 std::shared_ptr<TelnetServer> telnetController(
nullptr);
179 vCheckFlag.emplace_back(
"Telnet Server", std::make_shared<std::atomic_flag>(
false));
180 const unsigned long telnetPort =
182 if (telnetPort > 0 && telnetPort < 65536)
186 telnetController = std::make_shared<TelnetServer>();
191 mainPrometheusServer ? mainPrometheusServer->createNewRegistry() :
nullptr);
193 catch (
const std::exception &e)
195 spdlog::error(
"Can't start Telnet Server: {}", e.what());
199 else if (telnetPort != 0)
201 spdlog::error(
"Invalid Telnet port: {}", telnetPort);
213 while (interruptFlag == 0)
215 std::this_thread::sleep_for(std::chrono::milliseconds(500));
226 curl_global_cleanup();
constexpr uintmax_t alarmInterval
int main(int argc, char **argv)