37int main(
int argc,
char **argv)
43 if (curl_global_init(CURL_GLOBAL_DEFAULT) < 0)
45 spdlog::critical(
"Can't init curl");
52 throw std::invalid_argument(std::format(
"{} {}",
"Failed to load configuration:", config.
getLastError()));
55 const MainLogger logger(config.
get(
"LOKI_ADDRESS"), config.
get(
"SENTRY_ADDRESS"));
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));
182 unsigned long telnetPort = 0;
185 telnetPort = std::stoul(input.
getCmdOption(
"--enable-telnet"));
186 if (telnetPort < 1 || telnetPort > 65535)
188 throw std::invalid_argument(
"out of range");
191 catch (
const std::exception &e)
193 spdlog::error(
"Invalid Telnet port: {} {}", telnetPort, e.what());
199 telnetController = std::make_shared<TelnetServer>();
204 mainPrometheusServer ? mainPrometheusServer->createNewRegistry() :
nullptr);
206 catch (
const std::exception &e)
208 spdlog::error(
"Can't start Telnet Server: {}", e.what());
221 while (interruptFlag == 0)
223 std::this_thread::sleep_for(std::chrono::milliseconds(500));
234 curl_global_cleanup();
constexpr uintmax_t alarmInterval
int main(int argc, char **argv)