added 'netstats' query command to wesnothd...
...to query for current network transfer info
This commit is contained in:
parent
ede8e6e41d
commit
9cd66a8cae
5 changed files with 37 additions and 3 deletions
|
@ -223,6 +223,11 @@ void error::disconnect()
|
|||
if(socket) network::disconnect(socket);
|
||||
}
|
||||
|
||||
pending_statistics get_pending_stats()
|
||||
{
|
||||
return network_worker_pool::get_pending_stats();
|
||||
}
|
||||
|
||||
manager::manager(size_t min_threads, size_t max_threads) : free_(true)
|
||||
{
|
||||
// If the network is already being managed
|
||||
|
|
|
@ -34,6 +34,13 @@ namespace threading
|
|||
|
||||
namespace network {
|
||||
|
||||
struct pending_statistics {
|
||||
int npending_sends;
|
||||
int nbytes_pending_sends;
|
||||
};
|
||||
|
||||
pending_statistics get_pending_stats();
|
||||
|
||||
// A network manager must be created before networking can be used.
|
||||
// It must be destroyed only after all networking activity stops.
|
||||
|
||||
|
|
|
@ -100,7 +100,6 @@ unsigned int waiting_threads[NUM_SHARDS];
|
|||
size_t min_threads = 0;
|
||||
size_t max_threads = 0;
|
||||
|
||||
|
||||
int get_shard(TCPsocket sock) { return intptr_t(sock)%NUM_SHARDS; }
|
||||
|
||||
struct buffer {
|
||||
|
@ -637,6 +636,22 @@ manager::~manager()
|
|||
}
|
||||
}
|
||||
|
||||
network::pending_statistics get_pending_stats()
|
||||
{
|
||||
network::pending_statistics stats;
|
||||
stats.npending_sends = 0;
|
||||
stats.nbytes_pending_sends = 0;
|
||||
for(int shard = 0; shard != NUM_SHARDS; ++shard) {
|
||||
const threading::lock lock(*shard_mutexes[shard]);
|
||||
stats.npending_sends += outgoing_bufs[shard].size();
|
||||
for(buffer_set::const_iterator i = outgoing_bufs[shard].begin(); i != outgoing_bufs[shard].end(); ++i) {
|
||||
stats.nbytes_pending_sends += (*i)->raw_buffer.size();
|
||||
}
|
||||
}
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
void set_raw_data_only()
|
||||
{
|
||||
raw_data_only = true;
|
||||
|
|
|
@ -36,6 +36,8 @@ private:
|
|||
bool active_;
|
||||
};
|
||||
|
||||
network::pending_statistics get_pending_stats();
|
||||
|
||||
void set_raw_data_only();
|
||||
|
||||
//! Function to asynchronously received data to the given socket.
|
||||
|
|
|
@ -812,7 +812,7 @@ void server::process_query(const network::connection sock,
|
|||
} else if (command == "status") {
|
||||
response << process_command(command.to_string() + " " + pl->second.name());
|
||||
} else if (command == "status " + pl->second.name() || command == "metrics"
|
||||
|| command == "motd" || command == "wml") {
|
||||
|| command == "motd" || command == "wml" || command == "netstats") {
|
||||
response << process_command(command.to_string());
|
||||
} else if (command == admin_passwd_) {
|
||||
LOG_SERVER << "New Admin recognized:" << "\tIP: "
|
||||
|
@ -838,7 +838,7 @@ std::string server::process_command(const std::string& query) {
|
|||
std::string parameters = (i == query.end() ? "" : std::string(i+1,query.end()));
|
||||
utils::strip(parameters);
|
||||
const std::string& help_msg = "Available commands are: (k)ban(s) [<mask>],"
|
||||
"kick <mask>, help, metrics, (lobby)msg <message>, motd [<message>],"
|
||||
"kick <mask>, help, metrics, netstats, (lobby)msg <message>, motd [<message>],"
|
||||
"status [<mask>], unban <ipmask>";
|
||||
if (command == "shut_down") {
|
||||
throw network::error("shut down");
|
||||
|
@ -850,6 +850,11 @@ std::string server::process_command(const std::string& query) {
|
|||
"Number of users in the lobby = " << lobby_.nobservers() << "\n";
|
||||
} else if (command == "wml") {
|
||||
out << simple_wml::document::stats();
|
||||
} else if (command == "netstats") {
|
||||
network::pending_statistics stats = network::get_pending_stats();
|
||||
out << "Network stats:\nPending send buffers: "
|
||||
<< stats.npending_sends << "\nBytes in buffers: "
|
||||
<< stats.nbytes_pending_sends << "\n";
|
||||
} else if (command == "msg" || command == "lobbymsg") {
|
||||
if (parameters == "") {
|
||||
return "You must type a message.";
|
||||
|
|
Loading…
Add table
Reference in a new issue