]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/commands/cmd_stats.cpp
Add Channel::SetTopic(User *, std::string &) to set topic on a channel. Use it in...
[user/henk/code/inspircd.git] / src / commands / cmd_stats.cpp
index fafa9758174d4ff99b34d3905fee189f233adbcb..92be3b5fb41e66ee5fb39c8ac8d4a1444e4631ce 100644 (file)
 
 #include "inspircd.h"
 #ifndef WIN32
-#include <sys/resource.h>
-
-/* This is just to be completely certain that the change which fixed getrusage on RH7 doesn't break anything else -- Om */
-#ifndef RUSAGE_SELF
-#define RUSAGE_SELF 0
+       #include <sys/resource.h>
+       /* This is just to be completely certain that the change which fixed getrusage on RH7 doesn't break anything else -- Om */
+       #ifndef RUSAGE_SELF
+       #define RUSAGE_SELF 0
+       #endif
+#else
+       #include <psapi.h>
+       #pragma comment(lib, "psapi.lib")
 #endif
 
-#endif
 #include "xline.h"
 #include "commands/cmd_stats.h"
 #include "commands/cmd_whowas.h"
@@ -59,9 +61,14 @@ DllExport void DoStats(InspIRCd* ServerInstance, char statschar, User* user, str
        }
        
        int MOD_RESULT = 0;
-       FOREACH_RESULT(I_OnStats,OnStats(statschar,user,results));
+       FOREACH_RESULT(I_OnStats,OnStats(statschar, user, results));
        if (MOD_RESULT)
+       {
+               results.push_back(sn+" 219 "+user->nick+" "+statschar+" :End of /STATS report");
+               ServerInstance->SNO->WriteToSnoMask('t',"%s '%c' requested by %s (%s@%s)",
+                       (IS_LOCAL(user) ? "Stats" : "Remote stats"), statschar, user->nick.c_str(), user->ident.c_str(), user->host.c_str());
                return;
+       }
 
        switch (statschar)
        {
@@ -163,7 +170,7 @@ DllExport void DoStats(InspIRCd* ServerInstance, char statschar, User* user, str
 
                /* stats m (list number of times each command has been used, plus bytecount) */
                case 'm':
-                       for (Commandable::iterator i = ServerInstance->Parser->cmdlist.begin(); i != ServerInstance->Parser->cmdlist.end(); i++)
+                       for (Commandtable::iterator i = ServerInstance->Parser->cmdlist.begin(); i != ServerInstance->Parser->cmdlist.end(); i++)
                        {
                                if (i->second->use_count)
                                {
@@ -201,6 +208,19 @@ DllExport void DoStats(InspIRCd* ServerInstance, char statschar, User* user, str
 
                        results.push_back(sn+" 249 "+user->nick+" :MOTD(VECTOR) "+ConvToStr(ServerInstance->Config->MOTD.size())+", RULES(VECTOR) "+ConvToStr(ServerInstance->Config->RULES.size()));
 
+                       float kbitpersec_in, kbitpersec_out, kbitpersec_total;
+                       char kbitpersec_in_s[30], kbitpersec_out_s[30], kbitpersec_total_s[30];
+
+                       ServerInstance->SE->GetStats(kbitpersec_in, kbitpersec_out, kbitpersec_total);
+
+                       snprintf(kbitpersec_total_s, 30, "%03.5f%%", kbitpersec_total);
+                       snprintf(kbitpersec_out_s, 30, "%03.5f%%", kbitpersec_out);
+                       snprintf(kbitpersec_in_s, 30, "%03.5f%%", kbitpersec_in);
+
+                       results.push_back(sn+" 249 "+user->nick+" :Bandwidth total:  "+ConvToStr(kbitpersec_total_s)+" kilobits/sec");
+                       results.push_back(sn+" 249 "+user->nick+" :Bandwidth out:    "+ConvToStr(kbitpersec_out_s)+" kilobits/sec");
+                       results.push_back(sn+" 249 "+user->nick+" :Bandwidth in:     "+ConvToStr(kbitpersec_in_s)+" kilobits/sec");
+
 #ifndef WIN32
                        /* Moved this down here so all the not-windows stuff (look w00tie, I didn't say win32!) is in one ifndef.
                         * Also cuts out some identical code in both branches of the ifndef. -- Om
@@ -227,6 +247,14 @@ DllExport void DoStats(InspIRCd* ServerInstance, char statschar, User* user, str
                                snprintf(percent, 30, "%03.5f%%", per);
                                results.push_back(sn+" 249 "+user->nick+" :CPU Usage: "+percent);
                        }
+#else
+                       PROCESS_MEMORY_COUNTERS MemCounters;
+                       if (GetProcessMemoryInfo(GetCurrentProcess(), &MemCounters, sizeof(MemCounters)))
+                       {
+                               results.push_back(sn+" 249 "+user->nick+" :Total allocation: "+ConvToStr((MemCounters.WorkingSetSize + MemCounters.PagefileUsage) / 1024)+"K");
+                               results.push_back(sn+" 249 "+user->nick+" :Pagefile usage:   "+ConvToStr(MemCounters.PagefileUsage / 1024)+"K");
+                               results.push_back(sn+" 249 "+user->nick+" :Page faults:      "+ConvToStr(MemCounters.PageFaultCount));
+                       }
 #endif
                }
                break;