summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandManager.cpp83
-rw-r--r--src/Client/CommandManager.h6
-rw-r--r--src/Client/CommandParser.cpp21
-rw-r--r--src/Client/CommandParser.h1
-rw-r--r--src/Client/Requests/DaemonFSInfoRequest.cpp (renamed from src/Client/Requests/CoreStatusRequest.cpp)19
-rw-r--r--src/Client/Requests/DaemonFSInfoRequest.h (renamed from src/Client/Requests/CoreStatusRequest.h)19
-rw-r--r--src/Client/Requests/Makefile.am4
-rw-r--r--src/Client/Requests/Makefile.in10
8 files changed, 133 insertions, 30 deletions
diff --git a/src/Client/CommandManager.cpp b/src/Client/CommandManager.cpp
index 2a20b29..08a2780 100644
--- a/src/Client/CommandManager.cpp
+++ b/src/Client/CommandManager.cpp
@@ -20,9 +20,11 @@
#include "CommandManager.h"
#include <Common/HostInfo.h>
#include <Common/Logger.h>
+#include <Net/Packets/FSInfoPacket.h>
#include <Net/Packets/HostListPacket.h>
#include <Net/Packets/HostStatusPacket.h>
+#include <cmath>
#include <iostream>
#include <vector>
@@ -30,6 +32,48 @@
namespace Mad {
namespace Client {
+void CommandManager::printFSInfo(const Net::Packets::FSInfoPacket &packet) {
+ const std::string units[] = {
+ "kB", "MB", "GB", "TB", ""
+ };
+
+ const std::vector<Common::SystemBackend::FSInfo>& fsList = packet.getFSInfo();
+
+ for(std::vector<Common::SystemBackend::FSInfo>::const_iterator fs = fsList.begin(); fs != fsList.end(); ++fs) {
+ unsigned usedUnit = 0, totalUnit = 0;
+
+ float used = fs->used;
+ float total = fs->total;
+ float available = fs->available;
+
+ while(used >= 1024 && !units[usedUnit+1].empty()) {
+ ++usedUnit;
+ used /= 1024;
+ available /= 1024;
+ }
+
+ while(total >= 1024 && !units[totalUnit+1].empty()) {
+ ++totalUnit;
+ total /= 1024;
+ }
+
+ std::string nameString = fs->mountedOn + " (" + fs->fsName + ")";
+
+ if(nameString.length() < 32) {
+ nameString.resize(32, ' ');
+ }
+ else {
+ nameString += '\n';
+ nameString.resize(nameString.length() + 32, ' ');
+ }
+
+ std::printf("\t%s%.*f%s", nameString.c_str(), (used < 10) ? 2 : 1, used, (usedUnit == totalUnit) ? "" : (" " + units[usedUnit]).c_str());
+ std::printf("/%.*f %s (%.1f%%)\n", (total < 10) ? 2 : 1, total, units[totalUnit].c_str(), std::min(100*used/(used+available), 100.0f));
+ }
+
+ std::printf("\n");
+}
+
void CommandManager::printHostStatus(const Net::Packets::HostStatusPacket &packet) {
if(packet.getUptime()) {
unsigned long days = packet.getUptime()/86400;
@@ -82,11 +126,10 @@ void CommandManager::printHostStatus(const Net::Packets::HostStatusPacket &packe
}
}
-void CommandManager::coreStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request) {
+
+void CommandManager::daemonCommandRequestFinished(const Common::Request<> &request) {
try {
- const Net::Packets::HostStatusPacket &packet = request.getResult();
- std::cout << "Server status:" << std::endl;
- printHostStatus(packet);
+ request.getResult();
}
catch(Common::Exception &exception) {
Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str());
@@ -95,9 +138,11 @@ void CommandManager::coreStatusRequestFinished(const Common::Request<Net::Packet
requestFinished();
}
-void CommandManager::daemonCommandRequestFinished(const Common::Request<> &request) {
+void CommandManager::daemonFSInfoRequestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request) {
try {
- request.getResult();
+ const Net::Packets::FSInfoPacket &packet = request.getResult();
+ std::cout << "Host file system usage:" << std::endl;
+ printFSInfo(packet);
}
catch(Common::Exception &exception) {
Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str());
@@ -131,5 +176,31 @@ void CommandManager::disconnectRequestFinished(const Common::Request<> &request)
requestFinished();
}
+void CommandManager::fsInfoRequestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request) {
+ try {
+ const Net::Packets::FSInfoPacket &packet = request.getResult();
+ std::cout << "Server file system usage:" << std::endl;
+ printFSInfo(packet);
+ }
+ catch(Common::Exception &exception) {
+ Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str());
+ }
+
+ requestFinished();
+}
+
+void CommandManager::statusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request) {
+ try {
+ const Net::Packets::HostStatusPacket &packet = request.getResult();
+ std::cout << "Server status:" << std::endl;
+ printHostStatus(packet);
+ }
+ catch(Common::Exception &exception) {
+ Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str());
+ }
+
+ requestFinished();
+}
+
}
}
diff --git a/src/Client/CommandManager.h b/src/Client/CommandManager.h
index f93d07f..1937c0f 100644
--- a/src/Client/CommandManager.h
+++ b/src/Client/CommandManager.h
@@ -26,6 +26,7 @@ namespace Mad {
namespace Net {
namespace Packets {
+class FSInfoPacket;
class HostStatusPacket;
class HostListPacket;
}
@@ -49,12 +50,15 @@ class CommandManager {
finished();
}
+ void printFSInfo(const Net::Packets::FSInfoPacket &packet);
void printHostStatus(const Net::Packets::HostStatusPacket &packet);
- void coreStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request);
void daemonCommandRequestFinished(const Common::Request<> &request);
+ void daemonFSInfoRequestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request);
void daemonStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request);
void disconnectRequestFinished(const Common::Request<> &request);
+ void fsInfoRequestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request);
+ void statusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request);
public:
CommandManager() : activeRequests(0), disconnect(false) {}
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 135f771..ab3dd50 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -19,13 +19,15 @@
#include "CommandParser.h"
#include "InformationManager.h"
-#include "Requests/CoreStatusRequest.h"
+#include "Requests/DaemonFSInfoRequest.h"
#include "Requests/DaemonCommandRequest.h"
#include "Requests/DaemonStatusRequest.h"
#include <Common/Exception.h>
#include <Common/Logger.h>
#include <Common/RequestManager.h>
+#include <Common/Requests/FSInfoRequest.h>
#include <Common/Requests/DisconnectRequest.h>
+#include <Common/Requests/StatusRequest.h>
#include <Net/Packets/HostListPacket.h>
#include <Net/Packets/HostStatusPacket.h>
@@ -37,6 +39,7 @@ namespace Mad {
namespace Client {
const CommandParser::Command CommandParser::commands[] = {
+ {{"fsinfo", 0}, "fsinfo [host]", "Displays file system usage information", "Displays file system usage information of a host or the server (if no host is given).", &CommandParser::fsinfoCommand},
{{"help", "?", 0}, "help [command]", "Displays usage information about commands", "Displays usage information about a command. If no command is given, a list of all available commands is displayed.", &CommandParser::helpCommand},
{{"list_hosts", "hosts", 0}, "list_hosts [-a]", "Lists the currently active hosts", "Lists the currently active hosts.\n\n -a\tAlso list inactive hosts", &CommandParser::listHostsCommand},
{{"reboot", 0}, "reboot *|host...", "Reboots host", "Reboots hosts. * will reboot all hosts.", &CommandParser::rebootCommand},
@@ -102,6 +105,20 @@ std::map<std::string, Common::HostInfo> CommandParser::parseHostList(const std::
}
+void CommandParser::fsinfoCommand(const std::vector<std::string> &args) {
+ if(args.size() == 1)
+ Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::FSInfoRequest(sigc::mem_fun(commandManager, &CommandManager::fsInfoRequestFinished))));
+ else if(args.size() == 2)
+ Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::DaemonFSInfoRequest(args[1], sigc::mem_fun(commandManager, &CommandManager::daemonFSInfoRequestFinished))));
+ else {
+ Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str());
+ printUsage("fsinfo");
+ return;
+ }
+
+ commandManager.activeRequests++;
+}
+
void CommandParser::helpCommand(const std::vector<std::string> &args) {
if(args.size() == 1) {
std::cout << "Available commands:" << std::endl << std::endl;
@@ -221,7 +238,7 @@ void CommandParser::shutdownCommand(const std::vector<std::string> &args) {
void CommandParser::statusCommand(const std::vector<std::string> &args) {
if(args.size() == 1)
- Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::CoreStatusRequest(sigc::mem_fun(commandManager, &CommandManager::coreStatusRequestFinished))));
+ Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::StatusRequest(sigc::mem_fun(commandManager, &CommandManager::statusRequestFinished))));
else if(args.size() == 2)
Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::DaemonStatusRequest(args[1], sigc::mem_fun(commandManager, &CommandManager::daemonStatusRequestFinished))));
else {
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index daca0b9..660f548 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -60,6 +60,7 @@ class CommandParser {
std::map<std::string, Common::HostInfo> parseHostList(const std::vector<std::string> &args, bool mustBeActive = false);
+ void fsinfoCommand(const std::vector<std::string> &args);
void helpCommand(const std::vector<std::string> &args);
void listHostsCommand(const std::vector<std::string> &args);
void rebootCommand(const std::vector<std::string> &args);
diff --git a/src/Client/Requests/CoreStatusRequest.cpp b/src/Client/Requests/DaemonFSInfoRequest.cpp
index 69e3ecf..eb26cf4 100644
--- a/src/Client/Requests/CoreStatusRequest.cpp
+++ b/src/Client/Requests/DaemonFSInfoRequest.cpp
@@ -1,5 +1,5 @@
/*
- * CoreStatusRequest.cpp
+ * DaemonFSInfoRequest.cpp
*
* Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
*
@@ -17,24 +17,29 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "CoreStatusRequest.h"
+#include "DaemonFSInfoRequest.h"
#include <Net/Connection.h>
+#include <Net/Packets/ErrorPacket.h>
namespace Mad {
namespace Client {
namespace Requests {
-void CoreStatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- connection->send(Net::Packet(Net::Packet::STATUS, requestId));
+void DaemonFSInfoRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+ connection->send(Net::Packet(Net::Packet::DAEMON_FS_INFO, requestId, daemon.c_str(), daemon.length()));
}
-void CoreStatusRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::OK) {
+void DaemonFSInfoRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
+ if(packet.getType() == Net::Packet::ERROR) {
+ finishWithError(Net::Packets::ErrorPacket(packet).getException());
+ return;
+ }
+ else if(packet.getType() != Net::Packet::OK) {
finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
return; // TODO Logging
}
- finish(Net::Packets::HostStatusPacket(packet));
+ finish(Net::Packets::FSInfoPacket(packet));
}
}
diff --git a/src/Client/Requests/CoreStatusRequest.h b/src/Client/Requests/DaemonFSInfoRequest.h
index f57f4bf..d966b8d 100644
--- a/src/Client/Requests/CoreStatusRequest.h
+++ b/src/Client/Requests/DaemonFSInfoRequest.h
@@ -1,5 +1,5 @@
/*
- * CoreStatusRequest.h
+ * DaemonFSInfoRequest.h
*
* Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
*
@@ -17,27 +17,32 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef MAD_CLIENT_REQUESTS_CORESTATUSREQUEST_H_
-#define MAD_CLIENT_REQUESTS_CORESTATUSREQUEST_H_
+#ifndef MAD_CLIENT_REQUESTS_DAEMONFSINFOREQUEST_H_
+#define MAD_CLIENT_REQUESTS_DAEMONFSINFOREQUEST_H_
#include <Common/Request.h>
-#include <Net/Packets/HostStatusPacket.h>
+#include <Net/Packets/FSInfoPacket.h>
+
+#include <string>
namespace Mad {
namespace Client {
namespace Requests {
-class CoreStatusRequest : public Common::Request<Net::Packets::HostStatusPacket> {
+class DaemonFSInfoRequest : public Common::Request<Net::Packets::FSInfoPacket> {
+ private:
+ std::string daemon;
+
protected:
virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
public:
- CoreStatusRequest(slot_type slot) : Common::Request<Net::Packets::HostStatusPacket>(slot) {}
+ DaemonFSInfoRequest(const std::string &daemon0, slot_type slot) : Common::Request<Net::Packets::FSInfoPacket>(slot), daemon(daemon0) {}
};
}
}
}
-#endif /* MAD_CLIENT_REQUESTS_CORESTATUSREQUEST_H_ */
+#endif /* MAD_CLIENT_REQUESTS_DAEMONFSINFOREQUEST_H_ */
diff --git a/src/Client/Requests/Makefile.am b/src/Client/Requests/Makefile.am
index 8c4f542..a96b265 100644
--- a/src/Client/Requests/Makefile.am
+++ b/src/Client/Requests/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = CoreStatusRequest.cpp DaemonCommandRequest.cpp DaemonListRequest.cpp DaemonStatusRequest.cpp
+librequests_la_SOURCES = DaemonCommandRequest.cpp DaemonFSInfoRequest.cpp DaemonListRequest.cpp DaemonStatusRequest.cpp
-noinst_HEADERS = CoreStatusRequest.h DaemonCommandRequest.h DaemonListRequest.h DaemonStatusRequest.h
+noinst_HEADERS = DaemonCommandRequest.h DaemonFSInfoRequest.h DaemonListRequest.h DaemonStatusRequest.h
diff --git a/src/Client/Requests/Makefile.in b/src/Client/Requests/Makefile.in
index 9336dbb..a074523 100644
--- a/src/Client/Requests/Makefile.in
+++ b/src/Client/Requests/Makefile.in
@@ -48,8 +48,8 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
librequests_la_LIBADD =
-am_librequests_la_OBJECTS = CoreStatusRequest.lo \
- DaemonCommandRequest.lo DaemonListRequest.lo \
+am_librequests_la_OBJECTS = DaemonCommandRequest.lo \
+ DaemonFSInfoRequest.lo DaemonListRequest.lo \
DaemonStatusRequest.lo
librequests_la_OBJECTS = $(am_librequests_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
@@ -189,8 +189,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = CoreStatusRequest.cpp DaemonCommandRequest.cpp DaemonListRequest.cpp DaemonStatusRequest.cpp
-noinst_HEADERS = CoreStatusRequest.h DaemonCommandRequest.h DaemonListRequest.h DaemonStatusRequest.h
+librequests_la_SOURCES = DaemonCommandRequest.cpp DaemonFSInfoRequest.cpp DaemonListRequest.cpp DaemonStatusRequest.cpp
+noinst_HEADERS = DaemonCommandRequest.h DaemonFSInfoRequest.h DaemonListRequest.h DaemonStatusRequest.h
all: all-am
.SUFFIXES:
@@ -242,8 +242,8 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CoreStatusRequest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonCommandRequest.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonFSInfoRequest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonListRequest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequest.Plo@am__quote@