diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/cmd_stats.cpp | 11 | ||||
-rw-r--r-- | src/socketengine.cpp | 25 | ||||
-rw-r--r-- | src/socketengines/socketengine_iocp.cpp | 1 |
3 files changed, 37 insertions, 0 deletions
diff --git a/src/commands/cmd_stats.cpp b/src/commands/cmd_stats.cpp index 1296bf08a..0857adb44 100644 --- a/src/commands/cmd_stats.cpp +++ b/src/commands/cmd_stats.cpp @@ -201,6 +201,17 @@ 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; + ServerInstance->SE->GetStats(kbitpersec_in, kbitpersec_out, kbitpersec_total); + + snprintf(kbitspersec_total_s, 30, "%03.5f%%", kbitspersec_total); + snprintf(kbitspersec_out_s, 30, "%03.5f%%", kbitspersec_out); + snprintf(kbitspersec_in_s, 30, "%03.5f%%", kbitspersec_in); + + results.push_back(sn+" 249 "+user->nick+" :Bandwidth total: "+ConvToStr(kbitspersec_total_s)+" kilobits/sec"); + results.push_back(sn+" 249 "+user->nick+" :Bandwidth out: "+ConvToStr(kbitspersec_out_s)+" kilobits/sec"); + results.push_back(sn+" 249 "+user->nick+" :Bandwidth in: "+ConvToStr(kbitspersec_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 diff --git a/src/socketengine.cpp b/src/socketengine.cpp index dd80b7f94..90d25e060 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -62,6 +62,8 @@ void SocketEngine::WantWrite(EventHandler* eh) SocketEngine::SocketEngine(InspIRCd* Instance) : ServerInstance(Instance) { TotalEvents = WriteEvents = ReadEvents = ErrorEvents = 0; + lastempty = time(NULL); + indata = outdata = 0; } SocketEngine::~SocketEngine() @@ -174,21 +176,25 @@ int SocketEngine::GetSockName(EventHandler* fd, sockaddr *name, socklen_t* namel int SocketEngine::RecvFrom(EventHandler* fd, void *buf, size_t len, int flags, sockaddr *from, socklen_t *fromlen) { + this->UpdateStats(len, 0); return recvfrom(fd->GetFd(), (char*)buf, len, flags, from, fromlen); } int SocketEngine::Send(EventHandler* fd, const void *buf, size_t len, int flags) { + this->UpdateStats(0, len); return send(fd->GetFd(), (const char*)buf, len, flags); } int SocketEngine::Recv(EventHandler* fd, void *buf, size_t len, int flags) { + this->UpdateStats(len, 0); return recv(fd->GetFd(), (char*)buf, len, flags); } int SocketEngine::SendTo(EventHandler* fd, const void *buf, size_t len, int flags, const sockaddr *to, socklen_t tolen) { + this->UpdateStats(0, len); return sendto(fd->GetFd(), (const char*)buf, len, flags, to, tolen); } @@ -221,3 +227,22 @@ void SocketEngine::RecoverFromFork() { } +void SocketEngine::UpdateStats(size_t len_in, size_t len_out) +{ + if (lastempty + 1 > time(NULL)) + { + lastempty = time(NULL); + indata = outdata = 0; + } + indata += len_in; + outdata += len_out; +} + +void SocketEngine::GetStats(float &kbitpersec_in, float &kbitpersec_out, float &kbitpersec_total) +{ + float in_kbit = indata * 8; + float out_kbit = outdata * 8; + kbitpersec_total = ((in_kbit + out_kbit)) / 1024); + kbitpersec_in = in_kbit / 1024; + kbitpersec_out = out_kbit / 1024; +} diff --git a/src/socketengines/socketengine_iocp.cpp b/src/socketengines/socketengine_iocp.cpp index c1e97ce74..2a0c4d416 100644 --- a/src/socketengines/socketengine_iocp.cpp +++ b/src/socketengines/socketengine_iocp.cpp @@ -494,6 +494,7 @@ int IOCPEngine::GetSockName(EventHandler* fd, sockaddr *name, socklen_t* namelen int IOCPEngine::RecvFrom(EventHandler* fd, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) { + this->UpdateStats(len, 0); udp_overlap * ov = NULL; if (!fd->GetExt("windows_readevent", ov)) return -1; |