#ifndef SYSTEM_MONITOR_H #define SYSTEM_MONITOR_H #include #include #include // for standard integer types like uint64_t namespace SystemMonitor { // --- 1. 定义数据结构体 --- struct SystemInfo { std::string kernelVersion; std::string kernelRelease; std::string architecture; }; struct StorageDevice { std::string filesystem; std::string type; std::string totalSize; std::string usedSize; std::string availableSize; std::string usePercentage; std::string mountPoint; }; struct MemoryInfo { uint64_t total_kb = 0; // 未来可以添加 free, available, cached 等 }; struct ThermalInfo { std::string zoneName; double temperatureCelsius = 0.0; }; struct CpuUtilization { double totalUsagePercentage = 0.0; // 未来可以添加每个核心的利用率 }; // --- 2. 定义 SystemMonitor 类 --- class SystemMonitor { public: SystemMonitor() = default; // --- 数据采集接口 --- SystemInfo getSystemInfo() const; std::vector getStorageInfo() const; MemoryInfo getMemoryInfo() const; std::vector getChipTemperature() const; CpuUtilization getCpuUtilization(int interval_ms = 1000) const; std::string getKernelLogs(int last_n_lines = 20) const; private: // --- 核心工具函数(现在作为私有成员)--- std::string readFile(const std::string& filePath) const; std::string execCommand(const char* cmd) const; // 用于计算CPU利用率的内部状态 mutable uint64_t prev_idle_ = 0; mutable uint64_t prev_total_ = 0; }; } // namespace SystemMonitor #endif // SYSTEM_MONITOR_H