From b0ca04e1baf9a3405bfb50d7c3d95e8e425f4c3e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 12 Sep 2008 00:40:06 +0200 Subject: Serverstatus zeigt die Speicherauslastung an --- src/Common/Backends/Makefile.in | 2 ++ src/Common/Backends/SystemBackendProc.cpp | 49 ++++++++++++++++++++++++++++--- src/Common/Backends/SystemBackendProc.h | 3 +- 3 files changed, 49 insertions(+), 5 deletions(-) (limited to 'src/Common/Backends') diff --git a/src/Common/Backends/Makefile.in b/src/Common/Backends/Makefile.in index 431e582..3538513 100644 --- a/src/Common/Backends/Makefile.in +++ b/src/Common/Backends/Makefile.in @@ -119,6 +119,8 @@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PCRECPP_CFLAGS = @PCRECPP_CFLAGS@ +PCRECPP_LIBS = @PCRECPP_LIBS@ PKG_CONFIG = @PKG_CONFIG@ RANLIB = @RANLIB@ SED = @SED@ diff --git a/src/Common/Backends/SystemBackendProc.cpp b/src/Common/Backends/SystemBackendProc.cpp index d33fbf3..7e9fcbd 100644 --- a/src/Common/Backends/SystemBackendProc.cpp +++ b/src/Common/Backends/SystemBackendProc.cpp @@ -18,14 +18,18 @@ */ #include "SystemBackendProc.h" + #include +#include + +#include namespace Mad { namespace Common { namespace Backends { -SystemBackendProc::Uptime SystemBackendProc::getUptime() const { - Uptime uptime = {0, 0}; +SystemBackend::UptimeInfo SystemBackendProc::getUptimeInfo() const { + UptimeInfo uptime = {0, 0}; std::ifstream file("/proc/uptime"); @@ -37,17 +41,54 @@ SystemBackendProc::Uptime SystemBackendProc::getUptime() const { if(!file.good()) return uptime; - uptime.uptime = (uint32_t)f; + uptime.uptime = (unsigned long)f; file >> f; if(!file.good()) return uptime; - uptime.idleTime = (uint32_t)f; + uptime.idleTime = (unsigned long)f; return uptime; } +SystemBackend::MemoryInfo SystemBackendProc::getMemoryInfo() const { + MemoryInfo memInfo = {0, 0, 0, 0}; + + std::ifstream file("/proc/meminfo"); + + if(!file.good()) + return memInfo; + + pcrecpp::RE re("(.+):\\s*(\\d+).*"); + + while(!file.eof() && file.good()) { + std::string line; + std::getline(file, line); + + std::string name; + unsigned long value; + + if(!re.FullMatch(line, &name, &value)) + continue; + + if(name == "MemTotal") + memInfo.totalMem = value; + else if(name == "MemFree") + memInfo.freeMem = value; + else if(name == "SwapTotal") + memInfo.totalSwap = value; + else if(name == "SwapFree") + memInfo.freeSwap = value; + + if(memInfo.totalMem && memInfo.freeMem && memInfo.totalSwap && memInfo.freeSwap) + break; + } + + + return memInfo; +} + } } } diff --git a/src/Common/Backends/SystemBackendProc.h b/src/Common/Backends/SystemBackendProc.h index af34eee..cdcc3e7 100644 --- a/src/Common/Backends/SystemBackendProc.h +++ b/src/Common/Backends/SystemBackendProc.h @@ -35,7 +35,8 @@ class SystemBackendProc : public SystemBackend { setBackend(new SystemBackendProc()); } - virtual Uptime getUptime() const; + virtual UptimeInfo getUptimeInfo() const; + virtual MemoryInfo getMemoryInfo() const; }; } -- cgit v1.2.3