diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-06-18 20:27:47 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-06-18 20:27:47 +0000 |
commit | a3802dee4bdfcf3dc11df09c59e6ed1912fbadd9 (patch) | |
tree | 0c8a3cc293f02828aebedbbb1f5228cd627f3b2a /src/socketengine.cpp | |
parent | ed6fcd4a50f3a0d84ae07a8a0011b193e00cf088 (diff) |
Measure bandwidth statistics from the socket engine (kiloBITS per second in, out, total) and display them in /stats z plus send them via the named pipe to the windows gui
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9918 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/socketengine.cpp')
-rw-r--r-- | src/socketengine.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
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; +} |