Store IRCSocket connect_time, show bytes read/write per second in stats.py
This commit is contained in:
parent
503969abfd
commit
a3a2c1e5a4
2 changed files with 7 additions and 1 deletions
|
@ -49,6 +49,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
return {"networks": networks, "channels": channels, "users": users}
|
return {"networks": networks, "channels": channels, "users": users}
|
||||||
|
|
||||||
def _server_stats(self, server):
|
def _server_stats(self, server):
|
||||||
|
connected_seconds = time.time()-server.connect_time
|
||||||
return {
|
return {
|
||||||
"hostname": server.connection_params.hostname,
|
"hostname": server.connection_params.hostname,
|
||||||
"port": server.connection_params.port,
|
"port": server.connection_params.port,
|
||||||
|
@ -58,7 +59,10 @@ class Module(ModuleManager.BaseModule):
|
||||||
server.nickname, server.username, server.hostname),
|
server.nickname, server.username, server.hostname),
|
||||||
"users": len(server.users),
|
"users": len(server.users),
|
||||||
"bytes-written": server.socket.bytes_written,
|
"bytes-written": server.socket.bytes_written,
|
||||||
|
"bytes-written-per-second":
|
||||||
|
server.socket.bytes_written/connected_seconds,
|
||||||
"bytes-read": server.socket.bytes_read,
|
"bytes-read": server.socket.bytes_read,
|
||||||
|
"bytes-read-per-second": server.socket.bytes_read/connected_seconds,
|
||||||
"channels": {
|
"channels": {
|
||||||
c.name: self._channel_stats(c) for c in server.channels
|
c.name: self._channel_stats(c) for c in server.channels
|
||||||
},
|
},
|
||||||
|
|
|
@ -37,7 +37,8 @@ class Socket(IRCObject.Object):
|
||||||
self.last_read = time.monotonic()
|
self.last_read = time.monotonic()
|
||||||
self.last_send = None # type: typing.Optional[float]
|
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:
|
def fileno(self) -> int:
|
||||||
return self.cached_fileno or self._socket.fileno()
|
return self.cached_fileno or self._socket.fileno()
|
||||||
|
@ -61,6 +62,7 @@ class Socket(IRCObject.Object):
|
||||||
if self._tls:
|
if self._tls:
|
||||||
self._tls_wrap()
|
self._tls_wrap()
|
||||||
|
|
||||||
|
self.connect_time = time.time()
|
||||||
self.connected_ip = self._socket.getpeername()[0]
|
self.connected_ip = self._socket.getpeername()[0]
|
||||||
self.cached_fileno = self._socket.fileno()
|
self.cached_fileno = self._socket.fileno()
|
||||||
self.connected = True
|
self.connected = True
|
||||||
|
|
Loading…
Reference in a new issue