2025-09-30 18:34:50 +08:00
|
|
|
|
#include "spdlog/spdlog.h"
|
|
|
|
|
|
#include "tcp_server.h" // 引入我们新的服务头文件
|
2025-10-11 14:06:38 +08:00
|
|
|
|
#include "server_heartbeat.h"
|
|
|
|
|
|
#include "SystemMonitor.h"
|
2025-09-30 18:34:50 +08:00
|
|
|
|
#include <boost/asio.hpp>
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
2025-10-11 14:06:38 +08:00
|
|
|
|
// try {
|
|
|
|
|
|
// spdlog::info("Edge Proxy main program started.");
|
2025-09-30 18:34:50 +08:00
|
|
|
|
|
2025-10-11 14:06:38 +08:00
|
|
|
|
// // Boost.Asio 的核心 I/O 上下文/事件循环
|
|
|
|
|
|
// boost::asio::io_context io_context;
|
|
|
|
|
|
// //心跳检测
|
|
|
|
|
|
// // Heartbeat::start_server();
|
|
|
|
|
|
// // 创建我们的 TCP 服务实例,监听 9999 端口
|
|
|
|
|
|
// TCPServer tcp_service(io_context, 9999);
|
2025-09-30 18:34:50 +08:00
|
|
|
|
|
2025-10-11 14:06:38 +08:00
|
|
|
|
// // 在这里,未来您可以创建并启动其他服务...
|
|
|
|
|
|
// // e.g., UDPService udp_service(io_context, 8888);
|
2025-09-30 18:34:50 +08:00
|
|
|
|
|
2025-10-11 14:06:38 +08:00
|
|
|
|
// spdlog::info("All services initialized. Starting I/O event loop...");
|
2025-09-30 18:34:50 +08:00
|
|
|
|
|
2025-10-11 14:06:38 +08:00
|
|
|
|
// // 运行 I/O 上下文,这会阻塞并开始处理所有异步事件(如网络连接)
|
|
|
|
|
|
// io_context.run();
|
2025-09-30 18:34:50 +08:00
|
|
|
|
|
2025-10-11 14:06:38 +08:00
|
|
|
|
// spdlog::info("Edge Proxy main program finished.");
|
2025-09-30 18:34:50 +08:00
|
|
|
|
|
2025-10-11 14:06:38 +08:00
|
|
|
|
// } catch (const std::exception& e) {
|
|
|
|
|
|
// spdlog::error("Exception in main: {}", e.what());
|
|
|
|
|
|
// return 1;
|
|
|
|
|
|
// }
|
|
|
|
|
|
spdlog::set_level(spdlog::level::debug); // 设置为 debug 级别以查看更多信息
|
|
|
|
|
|
spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] [thread %t] %v"); // 更详细的日志模式
|
|
|
|
|
|
try {
|
|
|
|
|
|
boost::asio::io_context io_context;
|
|
|
|
|
|
const uint16_t port = 9999; // 服务器监听端口
|
|
|
|
|
|
TCPServer server(io_context, port);
|
|
|
|
|
|
spdlog::info("TCP Server is running on port {}. Press Ctrl+C to exit.", port);
|
|
|
|
|
|
io_context.run(); // 运行 Boost.Asio 的事件循环
|
|
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
|
|
spdlog::critical("Exception: {}", e.what());
|
2025-09-30 18:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-11 14:06:38 +08:00
|
|
|
|
//打印系统信息
|
|
|
|
|
|
SystemMonitor::printSystemInfo();
|
|
|
|
|
|
SystemMonitor::printStorageInfo();
|
|
|
|
|
|
SystemMonitor::printChipTemperature();
|
|
|
|
|
|
// 计算资源利用率,等待2秒
|
|
|
|
|
|
std::cout << "开始计算CPU利用率..." << std::endl;
|
|
|
|
|
|
SystemMonitor::printResourceUtilization(2000);
|
|
|
|
|
|
SystemMonitor::printSystemLogs();
|
|
|
|
|
|
std::cout << "\n系统监控任务完成。\n" << std::endl;
|
|
|
|
|
|
//
|
2025-09-30 18:34:50 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|