diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-09-20 11:59:36 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-09-20 11:59:36 +0200 |
commit | 89551ddfc2879530981eba3db9ab857b88409ad8 (patch) | |
tree | b0fa2c3d84201a3bce8d46c002a2e506a95f1c24 /src/Common/Backends | |
parent | 5286ffcb30e3005569199c45bca38dfbf346cec3 (diff) | |
download | mad-89551ddfc2879530981eba3db9ab857b88409ad8.tar mad-89551ddfc2879530981eba3db9ab857b88409ad8.zip |
Lese /proc/loadavg f?r weitere Statusinformationen aus
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(); }; } |