summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-06-18 20:27:47 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-06-18 20:27:47 +0000
commita3802dee4bdfcf3dc11df09c59e6ed1912fbadd9 (patch)
tree0c8a3cc293f02828aebedbbb1f5228cd627f3b2a
parented6fcd4a50f3a0d84ae07a8a0011b193e00cf088 (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
-rw-r--r--include/socketengine.h10
-rw-r--r--src/commands/cmd_stats.cpp11
-rw-r--r--src/socketengine.cpp25
-rw-r--r--src/socketengines/socketengine_iocp.cpp1
-rw-r--r--win/inspircd_namedpipe.cpp6
5 files changed, 53 insertions, 0 deletions
diff --git a/include/socketengine.h b/include/socketengine.h
index f647f4df3..f16ec3fea 100644
--- a/include/socketengine.h
+++ b/include/socketengine.h
@@ -170,6 +170,12 @@ protected:
EventHandler** ref;
int MAX_DESCRIPTORS;
+
+ size_t indata;
+ size_t outdata;
+ time_t lastempty;
+
+ void UpdateStats(size_t len_in, size_t len_out);
public:
double TotalEvents;
@@ -396,6 +402,10 @@ public:
* the shell or operating system on fatal error.
*/
virtual void RecoverFromFork();
+
+ /** Get data transfer statistics, kilobits per second in and out and total.
+ */
+ void GetStats(float &kbitpersec_in, float &kbitpersec_out, float &kbitpersec_total);
};
#endif
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;
diff --git a/win/inspircd_namedpipe.cpp b/win/inspircd_namedpipe.cpp
index 30aab9cd4..3f0f47fdf 100644
--- a/win/inspircd_namedpipe.cpp
+++ b/win/inspircd_namedpipe.cpp
@@ -62,9 +62,12 @@ void IPCThread::Run()
std::stringstream stat;
DWORD Written = 0;
+ float kbitpersec_in, kbitpersec_out, kbitpersec_total;
PROCESS_MEMORY_COUNTERS MemCounters;
+ ServerInstance->SE->GetStats(kbitpersec_in, kbitpersec_out, kbitpersec_total);
+
bool HaveMemoryStats = GetProcessMemoryInfo(GetCurrentProcess(), &MemCounters, sizeof(MemCounters));
stat << "name " << ServerInstance->Config->ServerName << std::endl;
@@ -77,6 +80,9 @@ void IPCThread::Run()
stat << "pid " << GetProcessId(GetCurrentProcess()) << std::endl;
stat << "request " << oldrequest << std::endl;
stat << "result " << this->GetResult() << std::endl;
+ stat << "kbitspersectotal " << kbitpersec_total << std::endl;
+ stat << "kbitspersecout " << kbitpersec_out << std::endl;
+ stat << "kbitspersecin " << kbitpersec_in << std::endl;
if (HaveMemoryStats)
{
stat << "workingset " << MemCounters.WorkingSetSize << std::endl;