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/Client/CommandParser.cpp | 52 ++++++++++++++++++++++++++++++------------ src/Client/Makefile.in | 2 ++ src/Client/Request/Makefile.in | 2 ++ 3 files changed, 42 insertions(+), 14 deletions(-) (limited to 'src/Client') 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 #include +#include 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@ -- cgit v1.2.3