diff options
Diffstat (limited to 'src/Common/Backends')
-rw-r--r-- | src/Common/Backends/SystemBackendProc.cpp | 20 | ||||
-rw-r--r-- | src/Common/Backends/SystemBackendProc.h | 4 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/Common/Backends/SystemBackendProc.cpp b/src/Common/Backends/SystemBackendProc.cpp index f2d9152..51e14f8 100644 --- a/src/Common/Backends/SystemBackendProc.cpp +++ b/src/Common/Backends/SystemBackendProc.cpp @@ -20,6 +20,7 @@ #include "SystemBackendProc.h" #include <pcrecpp.h> +#include <cstdio> namespace Mad { namespace Common { @@ -86,6 +87,25 @@ SystemBackend::MemoryInfo SystemBackendProc::getMemoryInfo() { return memInfo; } +SystemBackend::LoadInfo SystemBackendProc::getLoadInfo() { + LoadInfo loadInfo = {0, 0, 0, 0, 0}; + + loadFile.seekg(0, std::ios::beg); + + if(!loadFile.good()) + return loadInfo; + + std::string line; + std::getline(loadFile, line); + + if(line.empty()) + return loadInfo; + + std::sscanf(line.c_str(), "%f %f %f %lu/%lu", &loadInfo.loadAvg1, &loadInfo.loadAvg5, &loadInfo.loadAvg15, &loadInfo.currentLoad, &loadInfo.nProcesses); + + return loadInfo; +} + } } } diff --git a/src/Common/Backends/SystemBackendProc.h b/src/Common/Backends/SystemBackendProc.h index fb9ecf5..8caa080 100644 --- a/src/Common/Backends/SystemBackendProc.h +++ b/src/Common/Backends/SystemBackendProc.h @@ -32,8 +32,9 @@ class SystemBackendProc : public SystemBackend { private: std::ifstream uptimeFile; std::ifstream meminfoFile; + std::ifstream loadFile; - SystemBackendProc() : uptimeFile("/proc/uptime"), meminfoFile("/proc/meminfo") {} + SystemBackendProc() : uptimeFile("/proc/uptime"), meminfoFile("/proc/meminfo"), loadFile("/proc/loadavg") {} public: static void useBackend() { @@ -42,6 +43,7 @@ class SystemBackendProc : public SystemBackend { virtual UptimeInfo getUptimeInfo(); virtual MemoryInfo getMemoryInfo(); + virtual LoadInfo getLoadInfo(); }; } |