summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.in2
-rwxr-xr-xconfigure139
-rw-r--r--configure.ac5
-rw-r--r--src/Client/CommandParser.cpp52
-rw-r--r--src/Client/Makefile.in2
-rw-r--r--src/Client/Request/Makefile.in2
-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
-rw-r--r--src/Core/Makefile.in2
-rw-r--r--src/Core/RequestHandler/CoreStatusRequestHandler.h8
-rw-r--r--src/Core/RequestHandler/Makefile.in2
-rw-r--r--src/Makefile.in2
-rw-r--r--src/Net/Makefile.in2
-rw-r--r--src/Net/Packets/CoreStatusPacket.cpp10
-rw-r--r--src/Net/Packets/CoreStatusPacket.h37
-rw-r--r--src/Net/Packets/Makefile.in2
20 files changed, 281 insertions, 66 deletions
diff --git a/Makefile.in b/Makefile.in
index 47cb6bc..1e55582 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -124,6 +124,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/configure b/configure
index cc36801..5f68e5b 100755
--- a/configure
+++ b/configure
@@ -881,6 +881,8 @@ GnuTLS_CFLAGS
GnuTLS_LIBS
sigc_CFLAGS
sigc_LIBS
+PCRECPP_CFLAGS
+PCRECPP_LIBS
LIBOBJS
LTLIBOBJS'
ac_subst_files=''
@@ -903,7 +905,9 @@ PKG_CONFIG
GnuTLS_CFLAGS
GnuTLS_LIBS
sigc_CFLAGS
-sigc_LIBS'
+sigc_LIBS
+PCRECPP_CFLAGS
+PCRECPP_LIBS'
# Initialize some variables set by options.
@@ -1521,6 +1525,10 @@ Some influential environment variables:
GnuTLS_LIBS linker flags for GnuTLS, overriding pkg-config
sigc_CFLAGS C compiler flags for sigc, overriding pkg-config
sigc_LIBS linker flags for sigc, overriding pkg-config
+ PCRECPP_CFLAGS
+ C compiler flags for PCRECPP, overriding pkg-config
+ PCRECPP_LIBS
+ linker flags for PCRECPP, overriding pkg-config
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
@@ -5174,7 +5182,7 @@ ia64-*-hpux*)
;;
*-*-irix6*)
# Find out which ABI we are using.
- echo '#line 5177 "configure"' > conftest.$ac_ext
+ echo '#line 5185 "configure"' > conftest.$ac_ext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
@@ -7529,11 +7537,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:7532: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:7540: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:7536: \$? = $ac_status" >&5
+ echo "$as_me:7544: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -7819,11 +7827,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:7822: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:7830: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:7826: \$? = $ac_status" >&5
+ echo "$as_me:7834: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -7923,11 +7931,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:7926: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:7934: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:7930: \$? = $ac_status" >&5
+ echo "$as_me:7938: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -10300,7 +10308,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<EOF
-#line 10303 "configure"
+#line 10311 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -10400,7 +10408,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<EOF
-#line 10403 "configure"
+#line 10411 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -12801,11 +12809,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:12804: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:12812: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:12808: \$? = $ac_status" >&5
+ echo "$as_me:12816: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -12905,11 +12913,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:12908: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:12916: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:12912: \$? = $ac_status" >&5
+ echo "$as_me:12920: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -14503,11 +14511,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:14506: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:14514: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:14510: \$? = $ac_status" >&5
+ echo "$as_me:14518: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -14607,11 +14615,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:14610: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:14618: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:14614: \$? = $ac_status" >&5
+ echo "$as_me:14622: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -16827,11 +16835,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:16830: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:16838: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:16834: \$? = $ac_status" >&5
+ echo "$as_me:16842: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -17117,11 +17125,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:17120: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:17128: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:17124: \$? = $ac_status" >&5
+ echo "$as_me:17132: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -17221,11 +17229,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:17224: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:17232: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:17228: \$? = $ac_status" >&5
+ echo "$as_me:17236: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -20184,8 +20192,83 @@ echo "${ECHO_T}yes" >&6; }
:
fi
-CPPFLAGS="$GnuTLS_CFLAGS $sigc_CFLAGS $CPPFLAGS"
-LIBS="$GnuTLS_LIBS $sigc_LIBS $LIBS"
+pkg_failed=no
+{ echo "$as_me:$LINENO: checking for PCRECPP" >&5
+echo $ECHO_N "checking for PCRECPP... $ECHO_C" >&6; }
+
+if test -n "$PKG_CONFIG"; then
+ if test -n "$PCRECPP_CFLAGS"; then
+ pkg_cv_PCRECPP_CFLAGS="$PCRECPP_CFLAGS"
+ else
+ if test -n "$PKG_CONFIG" && \
+ { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"libpcrecpp\"") >&5
+ ($PKG_CONFIG --exists --print-errors "libpcrecpp") 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; then
+ pkg_cv_PCRECPP_CFLAGS=`$PKG_CONFIG --cflags "libpcrecpp" 2>/dev/null`
+else
+ pkg_failed=yes
+fi
+ fi
+else
+ pkg_failed=untried
+fi
+if test -n "$PKG_CONFIG"; then
+ if test -n "$PCRECPP_LIBS"; then
+ pkg_cv_PCRECPP_LIBS="$PCRECPP_LIBS"
+ else
+ if test -n "$PKG_CONFIG" && \
+ { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"libpcrecpp\"") >&5
+ ($PKG_CONFIG --exists --print-errors "libpcrecpp") 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; then
+ pkg_cv_PCRECPP_LIBS=`$PKG_CONFIG --libs "libpcrecpp" 2>/dev/null`
+else
+ pkg_failed=yes
+fi
+ fi
+else
+ pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+ _pkg_short_errors_supported=yes
+else
+ _pkg_short_errors_supported=no
+fi
+ if test $_pkg_short_errors_supported = yes; then
+ PCRECPP_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "libpcrecpp"`
+ else
+ PCRECPP_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "libpcrecpp"`
+ fi
+ # Put the nasty error message in config.log where it belongs
+ echo "$PCRECPP_PKG_ERRORS" >&5
+
+ { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+ { { echo "$as_me:$LINENO: error: Test for PCRECPP failed." >&5
+echo "$as_me: error: Test for PCRECPP failed." >&2;}
+ { (exit 1); exit 1; }; }
+elif test $pkg_failed = untried; then
+ { { echo "$as_me:$LINENO: error: Test for PCRECPP failed." >&5
+echo "$as_me: error: Test for PCRECPP failed." >&2;}
+ { (exit 1); exit 1; }; }
+else
+ PCRECPP_CFLAGS=$pkg_cv_PCRECPP_CFLAGS
+ PCRECPP_LIBS=$pkg_cv_PCRECPP_LIBS
+ { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+ :
+fi
+
+CPPFLAGS="$GnuTLS_CFLAGS $sigc_CFLAGS $PCRECPP_CFLAGS $CPPFLAGS"
+LIBS="$GnuTLS_LIBS $sigc_LIBS $PCRECPP_LIBS $LIBS"
{ echo "$as_me:$LINENO: checking for gss_init_sec_context in -lgssapi_krb5" >&5
@@ -22828,11 +22911,13 @@ GnuTLS_CFLAGS!$GnuTLS_CFLAGS$ac_delim
GnuTLS_LIBS!$GnuTLS_LIBS$ac_delim
sigc_CFLAGS!$sigc_CFLAGS$ac_delim
sigc_LIBS!$sigc_LIBS$ac_delim
+PCRECPP_CFLAGS!$PCRECPP_CFLAGS$ac_delim
+PCRECPP_LIBS!$PCRECPP_LIBS$ac_delim
LIBOBJS!$LIBOBJS$ac_delim
LTLIBOBJS!$LTLIBOBJS$ac_delim
_ACEOF
- if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 17; then
+ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 19; then
break
elif $ac_last_try; then
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
diff --git a/configure.ac b/configure.ac
index 2e17108..142af89 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,9 +22,10 @@ AC_PROG_LIBTOOL
# Checks for libraries.
PKG_CHECK_MODULES(GnuTLS, gnutls, , AC_MSG_ERROR(Test for GnuTLS failed.))
PKG_CHECK_MODULES(sigc, sigc++-2.0, , AC_MSG_ERROR(Test for SigC++ 2.0 failed.))
+PKG_CHECK_MODULES(PCRECPP, libpcrecpp, , AC_MSG_ERROR(Test for PCRECPP failed.))
-CPPFLAGS="$GnuTLS_CFLAGS $sigc_CFLAGS $CPPFLAGS"
-LIBS="$GnuTLS_LIBS $sigc_LIBS $LIBS"
+CPPFLAGS="$GnuTLS_CFLAGS $sigc_CFLAGS $PCRECPP_CFLAGS $CPPFLAGS"
+LIBS="$GnuTLS_LIBS $sigc_LIBS $PCRECPP_LIBS $LIBS"
AC_CHECK_LIB(gssapi_krb5, gss_init_sec_context, , AC_CHECK_LIB(gssapi, gss_init_sec_context, , AC_MSG_ERROR(Test for GSSAPI library failed.)))
AC_CHECK_LIB(readline, readline, , AC_MSG_ERROR(Test for GNU readline library failed.))
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 6f5f38b..47c06c3 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -22,6 +22,7 @@
#include <Common/Request/DisconnectRequest.h>
#include <iostream>
+#include <cstdio>
namespace Mad {
namespace Client {
@@ -102,28 +103,51 @@ void CommandParser::coreStatusRequestFinished(const Net::Packets::CoreStatusPack
unsigned long hours = (packet.getUptime()%86400)/3600;
unsigned long minutes = (packet.getUptime()%3600)/60;
- std::cout << "\tUptime: ";
+ std::printf("\tUptime:\t\t");
- if(days) std::cout << days << " days ";
+ if(days) std::printf("%lu days ", days);
- std::cout << hours << ":";
+ std::printf("%lu:%02lu", hours, minutes);
- std::streamsize width = std::cout.width(2);
- std::cout.fill('0');
- std::cout << minutes;
+ if(packet.getIdleTime())
+ std::printf(" (load average: %.1f%%)", 100.0f-(packet.getIdleTime()*100.0f/packet.getUptime()));
- std::cout.width(width);
+ std::printf("\n\n");
+ }
+
+ if(packet.getTotalMem() && packet.getFreeMem()) {
+ const std::string units[] = {
+ "kB", "MB", "GB", "TB", ""
+ };
+
+ unsigned unit = 0;
+ float totalMem = packet.getTotalMem(), usedMem = packet.getTotalMem()-packet.getFreeMem();
- if(packet.getIdleTime()) {
- std::streamsize prec = std::cout.precision(3);
- std::cout << " (load average: " << (100.0f-(packet.getIdleTime()*100.0f/packet.getUptime())) << "%)";
- std::cout.precision(prec);
+ while(totalMem >= 1024 && !units[unit+1].empty()) {
+ ++unit;
+ totalMem /= 1024;
+ usedMem /= 1024;
}
- std::cout << std::endl;
- }
+ std::printf("\tMemory usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].c_str());
+ std::printf(" (%.1f%%)\n", usedMem*100.0f/totalMem);
+
+ if(packet.getTotalSwap() && packet.getFreeSwap()) {
+ unit = 0;
+ totalMem = packet.getTotalSwap(); usedMem = packet.getTotalSwap()-packet.getFreeSwap();
- std::cout << std::endl;
+ while(totalMem >= 1024 && !units[unit+1].empty()) {
+ ++unit;
+ totalMem /= 1024;
+ usedMem /= 1024;
+ }
+
+ std::printf("\tSwap usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].c_str());
+ std::printf(" (%.1f%%)\n", usedMem*100.0f/totalMem);
+ }
+
+ std::printf("\n");
+ }
requestFinished();
}
diff --git a/src/Client/Makefile.in b/src/Client/Makefile.in
index 2263aff..423e2f3 100644
--- a/src/Client/Makefile.in
+++ b/src/Client/Makefile.in
@@ -129,6 +129,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/Client/Request/Makefile.in b/src/Client/Request/Makefile.in
index 804c5fb..1ac4924 100644
--- a/src/Client/Request/Makefile.in
+++ b/src/Client/Request/Makefile.in
@@ -100,6 +100,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/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;
}
diff --git a/src/Core/Makefile.in b/src/Core/Makefile.in
index 3590c7f..98a97e0 100644
--- a/src/Core/Makefile.in
+++ b/src/Core/Makefile.in
@@ -129,6 +129,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/Core/RequestHandler/CoreStatusRequestHandler.h b/src/Core/RequestHandler/CoreStatusRequestHandler.h
index eec0154..ec94bb5 100644
--- a/src/Core/RequestHandler/CoreStatusRequestHandler.h
+++ b/src/Core/RequestHandler/CoreStatusRequestHandler.h
@@ -44,9 +44,13 @@ class CoreStatusRequestHandler : public Common::RequestHandler {
if(packet.getType() != Net::Packet::TYPE_CORE_STATUS)
return false; // TODO Logging
- Common::SystemBackend::Uptime uptime = Common::SystemBackend::getBackend()->getUptime();
+ // TODO Require authentication
- if(!connection->send(Net::Packets::CoreStatusPacket(Net::Packet::TYPE_OK, packet.getRequestId(), uptime.uptime, uptime.idleTime)))
+ Common::SystemBackend::UptimeInfo uptimeInfo = Common::SystemBackend::getBackend()->getUptimeInfo();
+ Common::SystemBackend::MemoryInfo memInfo = Common::SystemBackend::getBackend()->getMemoryInfo();
+
+ if(!connection->send(Net::Packets::CoreStatusPacket(Net::Packet::TYPE_OK, packet.getRequestId(), uptimeInfo.uptime, uptimeInfo.idleTime,
+ memInfo.totalMem, memInfo.freeMem, memInfo.totalSwap, memInfo.freeSwap)))
return false;
setFinished();
diff --git a/src/Core/RequestHandler/Makefile.in b/src/Core/RequestHandler/Makefile.in
index bea3870..2d1cbee 100644
--- a/src/Core/RequestHandler/Makefile.in
+++ b/src/Core/RequestHandler/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/Makefile.in b/src/Makefile.in
index bee6a56..f5314e5 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -138,6 +138,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/Net/Makefile.in b/src/Net/Makefile.in
index e813a71..3d9f7bf 100644
--- a/src/Net/Makefile.in
+++ b/src/Net/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/Net/Packets/CoreStatusPacket.cpp b/src/Net/Packets/CoreStatusPacket.cpp
index 4397fa8..ad2a7fb 100644
--- a/src/Net/Packets/CoreStatusPacket.cpp
+++ b/src/Net/Packets/CoreStatusPacket.cpp
@@ -24,12 +24,20 @@ namespace Mad {
namespace Net {
namespace Packets {
-CoreStatusPacket::CoreStatusPacket(Type type, uint16_t requestId, uint32_t uptime, uint32_t idleTime) : Packet(type, requestId) {
+CoreStatusPacket::CoreStatusPacket(Type type, uint16_t requestId, uint32_t uptime, uint32_t idleTime,
+ uint32_t totalMem, uint32_t freeMem, uint32_t totalSwap, uint32_t freeSwap)
+: Packet(type, requestId)
+{
setLength(sizeof(CoreStatusData));
coreStatusData = (CoreStatusData*)&rawData->data;
coreStatusData->uptime = htonl(uptime);
coreStatusData->idleTime = htonl(idleTime);
+
+ coreStatusData->totalMem = htonl(totalMem);
+ coreStatusData->freeMem = htonl(freeMem);
+ coreStatusData->totalSwap = htonl(totalSwap);
+ coreStatusData->freeSwap = htonl(freeSwap);
}
CoreStatusPacket& CoreStatusPacket::operator=(const Packet &p) {
diff --git a/src/Net/Packets/CoreStatusPacket.h b/src/Net/Packets/CoreStatusPacket.h
index 14b022e..a19f8e7 100644
--- a/src/Net/Packets/CoreStatusPacket.h
+++ b/src/Net/Packets/CoreStatusPacket.h
@@ -27,33 +27,34 @@ namespace Net {
namespace Packets {
class CoreStatusPacket : public Packet {
+ private:
+ CoreStatusPacket& operator=(const CoreStatusPacket &p);
+ CoreStatusPacket(const CoreStatusPacket &p);
+
protected:
struct CoreStatusData {
uint32_t uptime;
uint32_t idleTime;
+
+ uint32_t totalMem;
+ uint32_t freeMem;
+ uint32_t totalSwap;
+ uint32_t freeSwap;
};
CoreStatusData *coreStatusData;
public:
- CoreStatusPacket(Type type, uint16_t requestId, uint32_t uptime = 0, uint32_t idleTime = 0);
+ CoreStatusPacket(Type type, uint16_t requestId, uint32_t uptime = 0, uint32_t idleTime = 0,
+ uint32_t totalMem = 0, uint32_t freeMem = 0, uint32_t totalSwap = 0, uint32_t freeSwap = 0);
CoreStatusPacket(const Packet &p) : Packet(p) {
setLength(sizeof(CoreStatusData));
coreStatusData = (CoreStatusData*)&rawData->data;
}
- CoreStatusPacket(const CoreStatusPacket &p) : Packet(p) {
- setLength(sizeof(CoreStatusData));
- coreStatusData = (CoreStatusData*)&rawData->data;
- }
-
CoreStatusPacket& operator=(const Packet &p);
- CoreStatusPacket& operator=(const CoreStatusPacket &p) {
- return (*this = (Packet)p);
- }
-
uint32_t getUptime() const {
return ntohl(coreStatusData->uptime);
}
@@ -61,6 +62,22 @@ class CoreStatusPacket : public Packet {
uint32_t getIdleTime() const {
return ntohl(coreStatusData->idleTime);
}
+
+ uint32_t getTotalMem() const {
+ return ntohl(coreStatusData->totalMem);
+ }
+
+ uint32_t getFreeMem() const {
+ return ntohl(coreStatusData->freeMem);
+ }
+
+ uint32_t getTotalSwap() const {
+ return ntohl(coreStatusData->totalSwap);
+ }
+
+ uint32_t getFreeSwap() const {
+ return ntohl(coreStatusData->freeSwap);
+ }
};
}
diff --git a/src/Net/Packets/Makefile.in b/src/Net/Packets/Makefile.in
index 8fa55b0..3af3051 100644
--- a/src/Net/Packets/Makefile.in
+++ b/src/Net/Packets/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@