36int main(
int argc,
char **argv)
40 const MainLogger logger(config.get(
"LOKI_ADDRESS"), config.get(
"SENTRY_ADDRESS"));
43 if (curl_global_init(CURL_GLOBAL_DEFAULT) < 0)
45 spdlog::critical(
"Can't init curl");
52 spdlog::set_level(spdlog::level::info);
56 spdlog::set_level(spdlog::level::debug);
60 spdlog::set_level(spdlog::level::trace);
64 spdlog::debug(
"======== Detected input arguments ========");
67 spdlog::debug(
"{} = {}", entry.first, entry.second);
71 spdlog::debug(
"======== Detected configuration ========");
72 for (
const auto &entry : config.getConfigMap())
74 spdlog::debug(
"{} = {}", entry.first, entry.second);
78 if (std::signal(SIGINT, interruptFunc) == SIG_ERR)
80 spdlog::critical(
"Can't set signal handler (SIGINT): {}",
getErrnoString(errno));
85 if (std::signal(SIGTERM, interruptFunc) == SIG_ERR)
87 spdlog::critical(
"Can't set signal handler (SIGTERM): {}",
getErrnoString(errno));
92 if (std::signal(SIGALRM, alarmFunc) == SIG_ERR)
94 spdlog::critical(
"Can't set signal handler (SIGALRM): {}",
getErrnoString(errno));
100 std::unique_ptr<Tracer> crashpadController(
nullptr);
101 vCheckFlag.emplace_back(
"Crashpad Handler", std::make_shared<std::atomic_flag>(
false));
102 crashpadController = std::make_unique<Tracer>(
103 vCheckFlag[
vCheckFlag.size() - 1].second, config.get(
"CRASHPAD_REMOTE"), config.get(
"CRASHPAD_PROXY"),
104 config.get(
"CRASHPAD_EXECUTABLE_DIR"), config.get(
"CRASHPAD_REPORT_DIR"));
107 std::unique_ptr<PrometheusServer> mainPrometheusServer(
nullptr);
108 const std::string prometheusAddr = input.
getCmdOption(
"--enable-prometheus");
109 if (!prometheusAddr.empty())
113 mainPrometheusServer = std::make_unique<PrometheusServer>(prometheusAddr);
114 spdlog::info(
"Prometheus server start at {}", prometheusAddr);
116 catch (
const std::exception &e)
118 spdlog::error(
"Can't start Prometheus Server: {}", e.what());
124 std::unique_ptr<ProcessMetrics> selfMonitor(
nullptr);
125 vCheckFlag.emplace_back(
"Self Monitor", std::make_shared<std::atomic_flag>(
false));
126 if (mainPrometheusServer)
129 mainPrometheusServer->createNewRegistry());
133 std::unique_ptr<ZeroMQServer> zmqController(
nullptr);
134 vCheckFlag.emplace_back(
"ZeroMQ Server", std::make_shared<std::atomic_flag>(
false));
135 const std::string zeromqServerAddr = input.
getCmdOption(
"--enable-zeromq");
136 if (!zeromqServerAddr.empty())
140 zmqController = std::make_unique<ZeroMQServer>(
142 mainPrometheusServer ? mainPrometheusServer->createNewRegistry() :
nullptr);
144 zmqController->initialise();
146 catch (
const std::exception &e)
148 spdlog::error(
"Can't start ZeroMQ Server: {}", e.what());
154 std::unique_ptr<TelnetServer> telnetController(
nullptr);
155 vCheckFlag.emplace_back(
"Telnet Server", std::make_shared<std::atomic_flag>(
false));
156 const unsigned long telnetPort =
158 if (telnetPort > 0 && telnetPort < 65536)
162 telnetController = std::make_unique<TelnetServer>();
167 mainPrometheusServer ? mainPrometheusServer->createNewRegistry() :
nullptr);
169 catch (
const std::exception &e)
171 spdlog::error(
"Can't start Telnet Server: {}", e.what());
175 else if (telnetPort != 0)
177 spdlog::error(
"Invalid Telnet port: {}", telnetPort);
191 std::this_thread::sleep_for(std::chrono::milliseconds(500));
202 curl_global_cleanup();
volatile sig_atomic_t interruptFlag
constexpr uintmax_t alarmInterval
int main(int argc, char **argv)