diff --git a/docs/rpc-interface.rst b/docs/rpc-interface.rst index 08e58c7..af1fb4a 100644 --- a/docs/rpc-interface.rst +++ b/docs/rpc-interface.rst @@ -84,6 +84,7 @@ A typical result is as follows (with annotated comments):: "pid": 85861, # Server's process ID "requests": 0, # Unprocessed requests across all sessions "sessions": 43, # Total number of sessions + "sessions_with_subs": 4, # Number of sessions with history subscriptions "subs": 84, # Script hash subscriptions across all sessions "txs_sent": 4, # Transactions sent since server started "uptime": "06h 48m 00s" # Time since server started diff --git a/electrumx/server/session.py b/electrumx/server/session.py index 6db7cae..8b4bf8b 100644 --- a/electrumx/server/session.py +++ b/electrumx/server/session.py @@ -293,6 +293,7 @@ class SessionManager(object): 'peers': self.peer_mgr.info(), 'requests': sum(s.count_pending_items() for s in self.sessions), 'sessions': self.session_count(), + 'sessions_with_subs': self.session_count_with_subs(), 'subs': self._sub_count(), 'txs_sent': self.txs_sent, 'uptime': util.formatted_time(time.time() - self.start_time), @@ -520,6 +521,11 @@ class SessionManager(object): '''The number of connections that we've sent something to.''' return len(self.sessions) + def session_count_with_subs(self): + '''The number of connections that have at least one hashX subscription.''' + return sum(len(session.hashX_subs) > 0 for session in self.sessions + if hasattr(session, 'hashX_subs')) + async def daemon_request(self, method, *args): '''Catch a DaemonError and convert it to an RPCError.''' try: