Made server automaticaly output bandwidth profiling stats to log

This commit is contained in:
Pauli Nieminen 2008-06-27 19:58:18 +00:00
parent 6b6c963ae0
commit ac9aff4f39
2 changed files with 14 additions and 3 deletions

View file

@ -894,14 +894,15 @@ static bandwidth_map::iterator add_bandwidth_entry(const std::string packet_type
int day = timeinfo->tm_mday;
assert(hour < 24 && hour >= 0);
std::pair<bandwidth_map::iterator,bool> insertion = hour_stats[hour].insert(std::make_pair(packet_type, bandwidth_stats()));
bandwidth_map::iterator& inserted = insertion.first;
if (!insertion.second && day != inserted->second.day)
{
// clear previuos day stats
hour[hour].clear();
hour_stats[hour].clear();
//insert again to cleared map
insertion = hour_stats[hour].insert(std::make_pair(packet_type, bandwidth_stats()));
inserted = insertion.first;
}
bandwidth_map::iterator inserted = insertion.first;
inserted->second.day = day;
return inserted;
}

View file

@ -483,6 +483,16 @@ void server::run() {
if ((loop%100) == 0 && last_ping_ + 10 <= now) {
// Make sure we log stats every 5 minutes
if (last_stats_ + 5*60 <= now) dump_stats(now);
#ifdef BANDWIDTH_MONITOR
// Send network stats every hour
static size_t prev_hour = localtime(&now)->tm_hour;
if (prev_hour != localtime(&now)->tm_hour)
{
prev_hour = localtime(&now)->tm_hour;
LOG_SERVER << network::get_bandwidth_stats();
}
#endif
// send a 'ping' to all players to detect ghosts
config ping;
ping["ping"] = lexical_cast<std::string>(now);
@ -849,7 +859,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 == "netstats" || command == "netstats all") {
|| command == "motd" || command == "wml" || command == "netstats") {
response << process_command(command.to_string());
} else if (command == admin_passwd_) {
LOG_SERVER << "New Admin recognized:" << "\tIP: "