1 /*
2    Copyright 2013-2014 EditShare, 2013-2015 Skytechnology sp. z o.o.
3 
4    This file is part of LizardFS.
5 
6    LizardFS is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, version 3.
9 
10    LizardFS is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with LizardFS. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "common/platform.h"
20 #include "admin/info_command.h"
21 
22 #include <iostream>
23 
24 #include "common/human_readable_format.h"
25 #include "common/lizardfs_statistics.h"
26 #include "common/lizardfs_version.h"
27 #include "common/server_connection.h"
28 
name() const29 std::string InfoCommand::name() const {
30 	return "info";
31 }
32 
supportedOptions() const33 LizardFsProbeCommand::SupportedOptions InfoCommand::supportedOptions() const {
34 	return {
35 		{kPorcelainMode, kPorcelainModeDescription},
36 	};
37 }
38 
usage() const39 void InfoCommand::usage() const {
40 	std::cerr << name() << " <master ip> <master port>\n";
41 	std::cerr << "    Prints statistics concerning the LizardFS installation.\n";
42 }
43 
run(const Options & options) const44 void InfoCommand::run(const Options& options) const {
45 	if (options.arguments().size() != 2) {
46 		throw WrongUsageException("Expected <master ip> and <master port> for " + name());
47 	}
48 
49 	ServerConnection connection(options.argument(0), options.argument(1));
50 	std::vector<uint8_t> request, response;
51 	serializeMooseFsPacket(request, CLTOMA_INFO);
52 	response = connection.sendAndReceive(request, MATOCL_INFO);
53 	LizardFsStatistics info;
54 	deserializeAllMooseFsPacketDataNoHeader(response, info);
55 	if (options.isSet(kPorcelainMode)) {
56 		std::cout << lizardfsVersionToString(info.version)
57 				<< ' ' << info.memoryUsage
58 				<< ' ' << info.totalSpace
59 				<< ' ' << info.availableSpace
60 				<< ' ' << info.trashSpace
61 				<< ' ' << info.trashNodes
62 				<< ' ' << info.reservedSpace
63 				<< ' ' << info.reservedNodes
64 				<< ' ' << info.allNodes
65 				<< ' ' << info.dirNodes
66 				<< ' ' << info.fileNodes
67 				<< ' ' << info.chunks
68 				<< ' ' << info.chunkCopies
69 				<< ' ' << info.chunkCopies // deprecated 'regular' copies
70 				<< std::endl;
71 	} else {
72 		std::cout << "LizardFS v" << lizardfsVersionToString(info.version) << '\n'
73 				<< "Memory usage:\t" << convertToIec(info.memoryUsage) << "B\n"
74 				<< "Total space:\t" << convertToIec(info.totalSpace) << "B\n"
75 				<< "Available space:\t" << convertToIec(info.availableSpace) << "B\n"
76 				<< "Trash space:\t" << convertToIec(info.trashSpace) << "B\n"
77 				<< "Trash files:\t" << info.trashNodes << '\n'
78 				<< "Reserved space:\t" << convertToIec(info.reservedSpace) << "B\n"
79 				<< "Reserved files:\t" << info.reservedNodes << '\n'
80 				<< "FS objects:\t" << info.allNodes << '\n'
81 				<< "Directories:\t" << info.dirNodes << '\n'
82 				<< "Files:\t" << info.fileNodes << '\n'
83 				<< "Chunks:\t" << info.chunks << '\n'
84 				<< "Chunk copies:\t" << info.chunkCopies << '\n'
85 				<< "Regular copies (deprecated):\t" << info.chunkCopies << std::endl;
86 	}
87 }
88