diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-09-12 00:40:06 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-09-12 00:40:06 +0200 |
commit | b0ca04e1baf9a3405bfb50d7c3d95e8e425f4c3e (patch) | |
tree | adf91aa4677d508ffe3ad1a6500ec03e8bc8c11e /src/Common/Backends | |
parent | 668437afdfb8d8a6bdaaaba6225177295e49982a (diff) | |
download | mad-b0ca04e1baf9a3405bfb50d7c3d95e8e425f4c3e.tar mad-b0ca04e1baf9a3405bfb50d7c3d95e8e425f4c3e.zip |
Serverstatus zeigt die Speicherauslastung an
Diffstat (limited to 'src/Common/Backends')
-rw-r--r-- | src/Common/Backends/Makefile.in | 2 | ||||
-rw-r--r-- | src/Common/Backends/SystemBackendProc.cpp | 49 | ||||
-rw-r--r-- | src/Common/Backends/SystemBackendProc.h | 3 |
3 files changed, 49 insertions, 5 deletions
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 <fstream> +#include <pcrecpp.h> + +#include <iostream> 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; }; } |