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 +- src/Common/Makefile.in | 2 ++ src/Common/Request/Makefile.in | 2 ++ src/Common/SystemBackend.h | 22 ++++++++++---- 6 files changed, 70 insertions(+), 10 deletions(-) (limited to 'src/Common') 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; }; } diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in index 7c805e9..95a5c35 100644 --- a/src/Common/Makefile.in +++ b/src/Common/Makefile.in @@ -130,6 +130,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/Request/Makefile.in b/src/Common/Request/Makefile.in index 8d53cc0..6c3b68d 100644 --- a/src/Common/Request/Makefile.in +++ b/src/Common/Request/Makefile.in @@ -102,6 +102,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/SystemBackend.h b/src/Common/SystemBackend.h index f88ddd9..6929c8d 100644 --- a/src/Common/SystemBackend.h +++ b/src/Common/SystemBackend.h @@ -38,15 +38,27 @@ class SystemBackend { } public: - struct Uptime { - uint32_t uptime; - uint32_t idleTime; + struct UptimeInfo { + unsigned long uptime; + unsigned long idleTime; + }; + + struct MemoryInfo { + unsigned long totalMem; + unsigned long freeMem; + unsigned long totalSwap; + unsigned long freeSwap; }; virtual ~SystemBackend() {} - virtual Uptime getUptime() const { - Uptime ret = {0, 0}; + virtual UptimeInfo getUptimeInfo() const { + UptimeInfo ret = {0, 0}; + return ret; + } + + virtual MemoryInfo getMemoryInfo() const { + MemoryInfo ret = {0, 0, 0, 0}; return ret; } -- cgit v1.2.3