summaryrefslogtreecommitdiffstats
path: root/src/Client/CommandParser.cpp
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-09-12 00:40:06 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-09-12 00:40:06 +0200
commitb0ca04e1baf9a3405bfb50d7c3d95e8e425f4c3e (patch)
treeadf91aa4677d508ffe3ad1a6500ec03e8bc8c11e /src/Client/CommandParser.cpp
parent668437afdfb8d8a6bdaaaba6225177295e49982a (diff)
downloadmad-b0ca04e1baf9a3405bfb50d7c3d95e8e425f4c3e.tar
mad-b0ca04e1baf9a3405bfb50d7c3d95e8e425f4c3e.zip
Serverstatus zeigt die Speicherauslastung an
Diffstat (limited to 'src/Client/CommandParser.cpp')
-rw-r--r--src/Client/CommandParser.cpp52
1 files changed, 38 insertions, 14 deletions
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();
}