summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Backends/Makefile.in2
-rw-r--r--src/Common/Backends/SystemBackendProc.cpp49
-rw-r--r--src/Common/Backends/SystemBackendProc.h3
-rw-r--r--src/Common/Makefile.in2
-rw-r--r--src/Common/Request/Makefile.in2
-rw-r--r--src/Common/SystemBackend.h22
6 files changed, 70 insertions, 10 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;
};
}
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;
}