From a3a2c1e5a471b425d971dfb776ba324266b2881b Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 24 May 2019 17:32:59 +0100 Subject: [PATCH] Store IRCSocket connect_time, show bytes read/write per second in stats.py --- modules/stats.py | 4 ++++ src/IRCSocket.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/stats.py b/modules/stats.py index d25f6914..e8f1ea5b 100644 --- a/modules/stats.py +++ b/modules/stats.py @@ -49,6 +49,7 @@ class Module(ModuleManager.BaseModule): return {"networks": networks, "channels": channels, "users": users} def _server_stats(self, server): + connected_seconds = time.time()-server.connect_time return { "hostname": server.connection_params.hostname, "port": server.connection_params.port, @@ -58,7 +59,10 @@ class Module(ModuleManager.BaseModule): server.nickname, server.username, server.hostname), "users": len(server.users), "bytes-written": server.socket.bytes_written, + "bytes-written-per-second": + server.socket.bytes_written/connected_seconds, "bytes-read": server.socket.bytes_read, + "bytes-read-per-second": server.socket.bytes_read/connected_seconds, "channels": { c.name: self._channel_stats(c) for c in server.channels }, diff --git a/src/IRCSocket.py b/src/IRCSocket.py index 3c32f64f..82c736ee 100644 --- a/src/IRCSocket.py +++ b/src/IRCSocket.py @@ -37,7 +37,8 @@ class Socket(IRCObject.Object): self.last_read = time.monotonic() self.last_send = None # type: typing.Optional[float] - self.connected_ip = None + self.connected_ip = None # type: typing.Optional[str] + self.conncect_time: float = -1 def fileno(self) -> int: return self.cached_fileno or self._socket.fileno() @@ -61,6 +62,7 @@ class Socket(IRCObject.Object): if self._tls: self._tls_wrap() + self.connect_time = time.time() self.connected_ip = self._socket.getpeername()[0] self.cached_fileno = self._socket.fileno() self.connected = True