From 89551ddfc2879530981eba3db9ab857b88409ad8 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 20 Sep 2008 11:59:36 +0200 Subject: Lese /proc/loadavg f?r weitere Statusinformationen aus --- src/Common/Backends/SystemBackendProc.cpp | 20 ++++++++++++++++++++ src/Common/Backends/SystemBackendProc.h | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'src/Common/Backends') 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 +#include 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(); }; } -- cgit v1.2.3