split parts of the metrics command into games, samples and stats commands

This commit is contained in:
Gunter Labes 2008-09-16 19:03:56 +00:00
parent 9427443283
commit 4168e62d4f
3 changed files with 52 additions and 27 deletions

View file

@ -102,6 +102,42 @@ void metrics::game_terminated(const std::string& reason)
terminations_[reason]++;
}
std::ostream& metrics::games(std::ostream& out)
{
if (terminations_.empty()) return out;
size_t n = 0;
out << "Games have been terminated in the following ways: \n";
for(std::map<std::string,int>::const_iterator i = terminations_.begin(); i != terminations_.end(); ++i) {
out << i->first << ": " << i->second << "\n";
++n;
}
out << "Total number of games = " << n;
return out;
}
std::ostream& metrics::samples(std::ostream& out)
{
if (samples_.empty()) return out;
std::vector<metrics::sample> ordered_samples = samples_;
std::sort(ordered_samples.begin(), ordered_samples.end(), compare_samples_by_time());
out << "Request types:\n";
size_t n = 0;
for(std::vector<metrics::sample>::const_iterator s = ordered_samples.begin(); s != ordered_samples.end(); ++s) {
out << "'" << s->name << "' called " << s->nsamples << " times "
<< s->parsing_time << "("<< s->max_parsing_time <<") parsing time, "
<< s->processing_time << "("<<s->max_processing_time<<") processing time\n";
++n;
}
out << "Total number of games = " << n;
return out;
}
std::ostream& operator<<(std::ostream& out, metrics& met)
{
const time_t time_up = time(NULL) - met.started_at_;
@ -116,26 +152,7 @@ std::ostream& operator<<(std::ostream& out, metrics& met)
<< met.nrequests_ << " requests serviced. " << requests_immediate
<< " (" << percent_immediate << "%) "
<< " requests were serviced immediately\n"
<< "longest burst of requests was " << met.most_consecutive_requests_ << "\n";
if(met.terminations_.empty() == false) {
out << "Games have been terminated in the following ways: \n";
for(std::map<std::string,int>::const_iterator i = met.terminations_.begin(); i != met.terminations_.end(); ++i) {
out << i->first << ": " << i->second << "\n";
}
}
std::vector<metrics::sample> ordered_samples = met.samples_;
std::sort(ordered_samples.begin(), ordered_samples.end(), compare_samples_by_time());
out << "\n\nRequest types:\n";
for(std::vector<metrics::sample>::const_iterator s = ordered_samples.begin(); s != ordered_samples.end(); ++s) {
out << "'" << s->name
<< "' called " << s->nsamples << " times "
<< s->parsing_time << "("<< s->max_parsing_time <<") parsing time, "
<< s->processing_time << "("<<s->max_processing_time<<") processing time\n";
}
<< "longest burst of requests was " << met.most_consecutive_requests_;
return out;
}

View file

@ -39,6 +39,8 @@ public:
void game_terminated(const std::string& reason);
std::ostream& games(std::ostream& out);
std::ostream& samples(std::ostream& out);
friend std::ostream& operator<<(std::ostream& out, metrics& met);
struct sample {

View file

@ -845,8 +845,8 @@ void server::process_query(const network::connection sock,
}
const simple_wml::string_span& command(query["type"]);
std::ostringstream response;
const std::string& help_msg = "Available commands are: help, metrics,"
" motd, netstats [all], status, wml.";
const std::string& help_msg = "Available commands are: help, games, metrics,"
" motd, netstats [all], samples, stats, status, wml.";
if (admins_.count(sock) != 0) {
LOG_SERVER << "Admin Command:" << "\ttype: " << command
<< "\tIP: "<< network::ip_address(sock)
@ -897,8 +897,8 @@ std::string server::process_command(const std::string& query, const std::string&
utils::strip(parameters);
const std::string& help_msg = "Available commands are: ban <mask> [<time>] <reason>,"
" bans [deleted], kick <mask>, k(ick)ban <mask> [<time>] <reason>,"
" help, metrics, netstats, (lobby)msg <message>, motd [<message>],"
" status [<mask>], unban <ipmask>";
" help, games, metrics, netstats, (lobby)msg <message>, motd [<message>],"
" samples, stats, status [<mask>], unban <ipmask>";
// Shutdown and restart commands can only be issued via the socket.
if (command == "shut_down" && issuer_name == "*socket*") {
if (parameters == "now") {
@ -930,10 +930,16 @@ std::string server::process_command(const std::string& query, const std::string&
}
} else if (command == "help") {
out << help_msg;
} else if (command == "stats") {
out << "Number of games = " << games_.size()
<< "\nTotal number of users = " << players_.size()
<< "\nNumber of users in the lobby = " << lobby_.nobservers();
} else if (command == "metrics") {
out << metrics_ << "Current number of games = " << games_.size() << "\n"
"Total number of users = " << players_.size() << "\n"
"Number of users in the lobby = " << lobby_.nobservers() << "\n";
out << metrics_;
} else if (command == "samples") {
metrics_.samples(out);
} else if (command == "games") {
metrics_.games(out);
} else if (command == "wml") {
out << simple_wml::document::stats();
} else if (command == "netstats") {