summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-10-31 17:06:32 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-10-31 17:06:32 +0000
commitbe77f42a97c06714c8c9388f791530dc243c17e6 (patch)
tree725b72a89c12feba7970c0aaeff4ff41b5b518b3
parente81b8faed7780a29c1b533741e2446ecea38f834 (diff)
Incorporate stats p patch by peaveydk (shows port numbers and number of clients on each port)
Tidy up cmd_stats.cpp in general, turn it into a large case statement git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5599 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/cmd_stats.cpp320
1 files changed, 172 insertions, 148 deletions
diff --git a/src/cmd_stats.cpp b/src/cmd_stats.cpp
index 6d2efd047..f82834229 100644
--- a/src/cmd_stats.cpp
+++ b/src/cmd_stats.cpp
@@ -57,192 +57,216 @@ void DoStats(InspIRCd* ServerInstance, char statschar, userrec* user, string_lis
if (MOD_RESULT)
return;
- if (statschar == 'c')
+ switch (statschar)
{
- /* This stats symbol must be handled by a linking module */
- }
+ /* stats p (show listening ports and registered clients on each) */
+ case 'p':
+ {
+ std::map<int,int> pc;
- if (statschar == 'i')
- {
- int idx = 0;
- for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
+ for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
+ {
+ userrec* t = (userrec*)(*i);
+ if (t->registered == REG_ALL)
+ pc[t->GetPort()]++;
+ }
+
+ for (unsigned int i = 0; i < ServerInstance->stats->BoundPortCount; i++)
+ {
+ results.push_back(sn+" 249 "+user->nick+" :p:"+ConvToStr(ServerInstance->Config->ports[i])+" (" + ConvToStr(pc[ServerInstance->Config->ports[i]])+" client" +
+ (pc[ServerInstance->Config->ports[i]] != 1 ? "s" : "") + ")");
+ }
+ }
+ break;
+
+ case 'c':
{
- results.push_back(sn+" 215 "+user->nick+" I * * * "+ConvToStr(MAXCLIENTS)+" "+ConvToStr(idx)+" "+ServerInstance->Config->ServerName+" *");
- idx++;
+ /* This stats symbol must be handled by a linking module */
}
- }
+ break;
- if (statschar == 'y')
- {
- int idx = 0;
- for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
+ case 'i':
{
- results.push_back(sn+" 218 "+user->nick+" Y "+ConvToStr(idx)+" 120 0 "+ConvToStr(i->flood)+" "+ConvToStr(i->registration_timeout));
- idx++;
+ int idx = 0;
+ for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
+ {
+ results.push_back(sn+" 215 "+user->nick+" I * * * "+ConvToStr(MAXCLIENTS)+" "+ConvToStr(idx)+" "+ServerInstance->Config->ServerName+" *");
+ idx++;
+ }
}
- }
+ break;
+
+ case 'Y':
+ {
+ int idx = 0;
+ for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
+ {
+ results.push_back(sn+" 218 "+user->nick+" Y "+ConvToStr(idx)+" 120 0 "+ConvToStr(i->flood)+" "+ConvToStr(i->registration_timeout));
+ idx++;
+ }
+ }
+ break;
- if (statschar == 'U')
- {
- char ulined[MAXBUF];
- for (int i = 0; i < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "uline"); i++)
+ case 'U':
{
- ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "uline","server", i, ulined, MAXBUF);
- results.push_back(sn+" 248 "+user->nick+" U "+std::string(ulined));
+ char ulined[MAXBUF];
+ for (int i = 0; i < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "uline"); i++)
+ {
+ ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "uline","server", i, ulined, MAXBUF);
+ results.push_back(sn+" 248 "+user->nick+" U "+std::string(ulined));
+ }
}
- }
+ break;
- if (statschar == 'P')
- {
- int idx = 0;
- for (user_hash::iterator i = ServerInstance->clientlist.begin(); i != ServerInstance->clientlist.end(); i++)
+ case 'P':
{
- if ((*i->second->oper) && (!ServerInstance->ULine(i->second->server)))
+ int idx = 0;
+ for (user_hash::iterator i = ServerInstance->clientlist.begin(); i != ServerInstance->clientlist.end(); i++)
{
- results.push_back(sn+" 249 "+user->nick+" :"+i->second->nick+" ("+i->second->ident+"@"+i->second->dhost+") Idle: "+ConvToStr(ServerInstance->Time() - i->second->idle_lastmsg));
- idx++;
+ if ((*i->second->oper) && (!ServerInstance->ULine(i->second->server)))
+ {
+ results.push_back(sn+" 249 "+user->nick+" :"+i->second->nick+" ("+i->second->ident+"@"+i->second->dhost+") Idle: "+ConvToStr(ServerInstance->Time() - i->second->idle_lastmsg));
+ idx++;
+ }
}
+ results.push_back(sn+" 249 "+user->nick+" :"+ConvToStr(idx)+" OPER(s)");
}
- results.push_back(sn+" 249 "+user->nick+" :"+ConvToStr(idx)+" OPER(s)");
- }
+ break;
- if (statschar == 'k')
- {
- ServerInstance->XLines->stats_k(user,results);
- }
+ case 'k':
+ ServerInstance->XLines->stats_k(user,results);
+ break;
- if (statschar == 'g')
- {
- ServerInstance->XLines->stats_g(user,results);
- }
+ case 'g':
+ ServerInstance->XLines->stats_g(user,results);
+ break;
- if (statschar == 'q')
- {
- ServerInstance->XLines->stats_q(user,results);
- }
+ case 'q':
+ ServerInstance->XLines->stats_q(user,results);
+ break;
- if (statschar == 'Z')
- {
- ServerInstance->XLines->stats_z(user,results);
- }
+ case 'Z':
+ ServerInstance->XLines->stats_z(user,results);
+ break;
- if (statschar == 'e')
- {
- ServerInstance->XLines->stats_e(user,results);
- }
+ case 'e':
+ ServerInstance->XLines->stats_e(user,results);
+ break;
- /* stats m (list number of times each command has been used, plus bytecount) */
- if (statschar == 'm')
- {
- for (nspace::hash_map<std::string,command_t*>::iterator i = ServerInstance->Parser->cmdlist.begin(); i != ServerInstance->Parser->cmdlist.end(); i++)
- {
- if (i->second->use_count)
+ /* stats m (list number of times each command has been used, plus bytecount) */
+ case 'm':
+ for (nspace::hash_map<std::string,command_t*>::iterator i = ServerInstance->Parser->cmdlist.begin(); i != ServerInstance->Parser->cmdlist.end(); i++)
{
- /* RPL_STATSCOMMANDS */
- results.push_back(sn+" 212 "+user->nick+" "+i->second->command+" "+ConvToStr(i->second->use_count)+" "+ConvToStr(i->second->total_bytes));
+ if (i->second->use_count)
+ {
+ /* RPL_STATSCOMMANDS */
+ results.push_back(sn+" 212 "+user->nick+" "+i->second->command+" "+ConvToStr(i->second->use_count)+" "+ConvToStr(i->second->total_bytes));
+ }
}
- }
-
- }
+ break;
- /* stats z (debug and memory info) */
- if (statschar == 'z')
- {
- rusage R;
- results.push_back(sn+" 240 "+user->nick+" :InspIRCd(CLASS) "+ConvToStr(sizeof(InspIRCd))+" bytes");
- results.push_back(sn+" 249 "+user->nick+" :Users(HASH_MAP) "+ConvToStr(ServerInstance->clientlist.size())+" ("+ConvToStr(ServerInstance->clientlist.size()*sizeof(userrec))+" bytes, "+ConvToStr(ServerInstance->clientlist.bucket_count())+" buckets)");
- results.push_back(sn+" 249 "+user->nick+" :Channels(HASH_MAP) "+ConvToStr(ServerInstance->chanlist.size())+" ("+ConvToStr(ServerInstance->chanlist.size()*sizeof(chanrec))+" bytes, "+ConvToStr(ServerInstance->chanlist.bucket_count())+" buckets)");
- results.push_back(sn+" 249 "+user->nick+" :Commands(VECTOR) "+ConvToStr(ServerInstance->Parser->cmdlist.size())+" ("+ConvToStr(ServerInstance->Parser->cmdlist.size()*sizeof(command_t))+" bytes)");
- results.push_back(sn+" 249 "+user->nick+" :MOTD(VECTOR) "+ConvToStr(ServerInstance->Config->MOTD.size())+", RULES(VECTOR) "+ConvToStr(ServerInstance->Config->RULES.size()));
- results.push_back(sn+" 249 "+user->nick+" :Modules(VECTOR) "+ConvToStr(ServerInstance->modules.size())+" ("+ConvToStr(ServerInstance->modules.size()*sizeof(Module))+")");
- results.push_back(sn+" 249 "+user->nick+" :ClassFactories(VECTOR) "+ConvToStr(ServerInstance->factory.size())+" ("+ConvToStr(ServerInstance->factory.size()*sizeof(ircd_module))+")");
- if (!getrusage(0,&R)) /* RUSAGE_SELF */
+ /* stats z (debug and memory info) */
+ case 'z':
{
- results.push_back(sn+" 249 "+user->nick+" :Total allocation: "+ConvToStr(R.ru_maxrss)+"K");
- results.push_back(sn+" 249 "+user->nick+" :Signals: "+ConvToStr(R.ru_nsignals));
- results.push_back(sn+" 249 "+user->nick+" :Page faults: "+ConvToStr(R.ru_majflt));
- results.push_back(sn+" 249 "+user->nick+" :Swaps: "+ConvToStr(R.ru_nswap));
- results.push_back(sn+" 249 "+user->nick+" :Context Switches: "+ConvToStr(R.ru_nvcsw+R.ru_nivcsw));
+ rusage R;
+ results.push_back(sn+" 240 "+user->nick+" :InspIRCd(CLASS) "+ConvToStr(sizeof(InspIRCd))+" bytes");
+ results.push_back(sn+" 249 "+user->nick+" :Users(HASH_MAP) "+ConvToStr(ServerInstance->clientlist.size())+" ("+ConvToStr(ServerInstance->clientlist.size()*sizeof(userrec))+" bytes, "+ConvToStr(ServerInstance->clientlist.bucket_count())+" buckets)");
+ results.push_back(sn+" 249 "+user->nick+" :Channels(HASH_MAP) "+ConvToStr(ServerInstance->chanlist.size())+" ("+ConvToStr(ServerInstance->chanlist.size()*sizeof(chanrec))+" bytes, "+ConvToStr(ServerInstance->chanlist.bucket_count())+" buckets)");
+ results.push_back(sn+" 249 "+user->nick+" :Commands(VECTOR) "+ConvToStr(ServerInstance->Parser->cmdlist.size())+" ("+ConvToStr(ServerInstance->Parser->cmdlist.size()*sizeof(command_t))+" bytes)");
+ results.push_back(sn+" 249 "+user->nick+" :MOTD(VECTOR) "+ConvToStr(ServerInstance->Config->MOTD.size())+", RULES(VECTOR) "+ConvToStr(ServerInstance->Config->RULES.size()));
+ results.push_back(sn+" 249 "+user->nick+" :Modules(VECTOR) "+ConvToStr(ServerInstance->modules.size())+" ("+ConvToStr(ServerInstance->modules.size()*sizeof(Module))+")");
+ results.push_back(sn+" 249 "+user->nick+" :ClassFactories(VECTOR) "+ConvToStr(ServerInstance->factory.size())+" ("+ConvToStr(ServerInstance->factory.size()*sizeof(ircd_module))+")");
+ if (!getrusage(0,&R)) /* RUSAGE_SELF */
+ {
+ results.push_back(sn+" 249 "+user->nick+" :Total allocation: "+ConvToStr(R.ru_maxrss)+"K");
+ results.push_back(sn+" 249 "+user->nick+" :Signals: "+ConvToStr(R.ru_nsignals));
+ results.push_back(sn+" 249 "+user->nick+" :Page faults: "+ConvToStr(R.ru_majflt));
+ results.push_back(sn+" 249 "+user->nick+" :Swaps: "+ConvToStr(R.ru_nswap));
+ results.push_back(sn+" 249 "+user->nick+" :Context Switches: "+ConvToStr(R.ru_nvcsw+R.ru_nivcsw));
+ }
}
- }
-
- if (statschar == 'T')
- {
- results.push_back(sn+" 249 "+user->nick+" :accepts "+ConvToStr(ServerInstance->stats->statsAccept)+" refused "+ConvToStr(ServerInstance->stats->statsRefused));
- results.push_back(sn+" 249 "+user->nick+" :unknown commands "+ConvToStr(ServerInstance->stats->statsUnknown));
- results.push_back(sn+" 249 "+user->nick+" :nick collisions "+ConvToStr(ServerInstance->stats->statsCollisions));
- results.push_back(sn+" 249 "+user->nick+" :dns requests "+ConvToStr(ServerInstance->stats->statsDnsGood+ServerInstance->stats->statsDnsBad)+" succeeded "+ConvToStr(ServerInstance->stats->statsDnsGood)+" failed "+ConvToStr(ServerInstance->stats->statsDnsBad));
- results.push_back(sn+" 249 "+user->nick+" :connection count "+ConvToStr(ServerInstance->stats->statsConnects));
- char buffer[MAXBUF];
- snprintf(buffer,MAXBUF," 249 %s :bytes sent %5.2fK recv %5.2fK",user->nick,ServerInstance->stats->statsSent / 1024,ServerInstance->stats->statsRecv / 1024);
- results.push_back(sn+buffer);
- }
-
- /* stats o */
- if (statschar == 'o')
- {
- for (int i = 0; i < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "oper"); i++)
+ break;
+
+ case 'T':
{
- char LoginName[MAXBUF];
- char HostName[MAXBUF];
- char OperType[MAXBUF];
- ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper","name", i, LoginName, MAXBUF);
- ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper","host", i, HostName, MAXBUF);
- ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper","type", i, OperType, MAXBUF);
- results.push_back(sn+" 243 "+user->nick+" O "+HostName+" * "+LoginName+" "+OperType+" 0");
+ char buffer[MAXBUF];
+ results.push_back(sn+" 249 "+user->nick+" :accepts "+ConvToStr(ServerInstance->stats->statsAccept)+" refused "+ConvToStr(ServerInstance->stats->statsRefused));
+ results.push_back(sn+" 249 "+user->nick+" :unknown commands "+ConvToStr(ServerInstance->stats->statsUnknown));
+ results.push_back(sn+" 249 "+user->nick+" :nick collisions "+ConvToStr(ServerInstance->stats->statsCollisions));
+ results.push_back(sn+" 249 "+user->nick+" :dns requests "+ConvToStr(ServerInstance->stats->statsDnsGood+ServerInstance->stats->statsDnsBad)+" succeeded "+ConvToStr(ServerInstance->stats->statsDnsGood)+" failed "+ConvToStr(ServerInstance->stats->statsDnsBad));
+ results.push_back(sn+" 249 "+user->nick+" :connection count "+ConvToStr(ServerInstance->stats->statsConnects));
+ snprintf(buffer,MAXBUF," 249 %s :bytes sent %5.2fK recv %5.2fK",user->nick,ServerInstance->stats->statsSent / 1024,ServerInstance->stats->statsRecv / 1024);
+ results.push_back(sn+buffer);
}
- }
+ break;
- /* stats l (show user I/O stats) */
- if (statschar == 'l')
- {
- results.push_back(sn+" 211 "+user->nick+" :nick[ident@host] sendq cmds_out bytes_out cmds_in bytes_in time_open");
- for (std::vector<userrec*>::iterator n = ServerInstance->local_users.begin(); n != ServerInstance->local_users.end(); n++)
- {
- userrec* i = *n;
- if (ServerInstance->IsNick(i->nick))
+ /* stats o */
+ case 'o':
+ for (int i = 0; i < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "oper"); i++)
{
- results.push_back(sn+" 211 "+user->nick+" "+i->nick+"["+i->ident+"@"+i->dhost+"] "+ConvToStr(i->sendq.length())+" "+ConvToStr(i->cmds_out)+" "+ConvToStr(i->bytes_out)+" "+ConvToStr(i->cmds_in)+" "+ConvToStr(i->bytes_in)+" "+ConvToStr(ServerInstance->Time() - i->age));
+ char LoginName[MAXBUF];
+ char HostName[MAXBUF];
+ char OperType[MAXBUF];
+ ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper","name", i, LoginName, MAXBUF);
+ ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper","host", i, HostName, MAXBUF);
+ ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper","type", i, OperType, MAXBUF);
+ results.push_back(sn+" 243 "+user->nick+" O "+HostName+" * "+LoginName+" "+OperType+" 0");
}
- }
- }
+ break;
+
+ /* stats l (show user I/O stats) */
+ case 'l':
+ results.push_back(sn+" 211 "+user->nick+" :nick[ident@host] sendq cmds_out bytes_out cmds_in bytes_in time_open");
+ for (std::vector<userrec*>::iterator n = ServerInstance->local_users.begin(); n != ServerInstance->local_users.end(); n++)
+ {
+ userrec* i = *n;
+ if (ServerInstance->IsNick(i->nick))
+ {
+ results.push_back(sn+" 211 "+user->nick+" "+i->nick+"["+i->ident+"@"+i->dhost+"] "+ConvToStr(i->sendq.length())+" "+ConvToStr(i->cmds_out)+" "+ConvToStr(i->bytes_out)+" "+ConvToStr(i->cmds_in)+" "+ConvToStr(i->bytes_in)+" "+ConvToStr(ServerInstance->Time() - i->age));
+ }
+ }
+ break;
/* stats L (show user I/O stats with IP addresses) */
- if (statschar == 'L')
- {
- results.push_back(sn+" 211 "+user->nick+" :nick[ident@ip] sendq cmds_out bytes_out cmds_in bytes_in time_open");
- for (std::vector<userrec*>::iterator n = ServerInstance->local_users.begin(); n != ServerInstance->local_users.end(); n++)
- {
- userrec* i = *n;
- if (ServerInstance->IsNick(i->nick))
+ case 'L':
+ results.push_back(sn+" 211 "+user->nick+" :nick[ident@ip] sendq cmds_out bytes_out cmds_in bytes_in time_open");
+ for (std::vector<userrec*>::iterator n = ServerInstance->local_users.begin(); n != ServerInstance->local_users.end(); n++)
{
- results.push_back(sn+" 211 "+user->nick+" "+i->nick+"["+i->ident+"@"+i->GetIPString()+"] "+ConvToStr(i->sendq.length())+" "+ConvToStr(i->cmds_out)+" "+ConvToStr(i->bytes_out)+" "+ConvToStr(i->cmds_in)+" "+ConvToStr(i->bytes_in)+" "+ConvToStr(ServerInstance->Time() - i->age));
+ userrec* i = *n;
+ if (ServerInstance->IsNick(i->nick))
+ {
+ results.push_back(sn+" 211 "+user->nick+" "+i->nick+"["+i->ident+"@"+i->GetIPString()+"] "+ConvToStr(i->sendq.length())+" "+ConvToStr(i->cmds_out)+" "+ConvToStr(i->bytes_out)+" "+ConvToStr(i->cmds_in)+" "+ConvToStr(i->bytes_in)+" "+ConvToStr(ServerInstance->Time() - i->age));
+ }
}
- }
- }
+ break;
- /* stats u (show server uptime) */
- if (statschar == 'u')
- {
- time_t current_time = 0;
- current_time = ServerInstance->Time();
- time_t server_uptime = current_time - ServerInstance->startup_time;
- struct tm* stime;
- stime = gmtime(&server_uptime);
- /* i dont know who the hell would have an ircd running for over a year nonstop, but
- * Craig suggested this, and it seemed a good idea so in it went */
- if (stime->tm_year > 70)
+ /* stats u (show server uptime) */
+ case 'u':
{
- char buffer[MAXBUF];
- snprintf(buffer,MAXBUF," 242 %s :Server up %d years, %d days, %.2d:%.2d:%.2d",user->nick,(stime->tm_year-70),stime->tm_yday,stime->tm_hour,stime->tm_min,stime->tm_sec);
- results.push_back(sn+buffer);
- }
- else
- {
- char buffer[MAXBUF];
- snprintf(buffer,MAXBUF," 242 %s :Server up %d days, %.2d:%.2d:%.2d",user->nick,stime->tm_yday,stime->tm_hour,stime->tm_min,stime->tm_sec);
- results.push_back(sn+buffer);
+ time_t current_time = 0;
+ current_time = ServerInstance->Time();
+ time_t server_uptime = current_time - ServerInstance->startup_time;
+ struct tm* stime;
+ stime = gmtime(&server_uptime);
+ /* i dont know who the hell would have an ircd running for over a year nonstop, but
+ * Craig suggested this, and it seemed a good idea so in it went */
+ if (stime->tm_year > 70)
+ {
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF," 242 %s :Server up %d years, %d days, %.2d:%.2d:%.2d",user->nick,(stime->tm_year-70),stime->tm_yday,stime->tm_hour,stime->tm_min,stime->tm_sec);
+ results.push_back(sn+buffer);
+ }
+ else
+ {
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF," 242 %s :Server up %d days, %.2d:%.2d:%.2d",user->nick,stime->tm_yday,stime->tm_hour,stime->tm_min,stime->tm_sec);
+ results.push_back(sn+buffer);
+ }
}
+ break;
+
+ default:
+ break;
}
results.push_back(sn+" 219 "+user->nick+" "+statschar+" :End of /STATS report");