diff --git a/lbry/wallet/server/prometheus.py b/lbry/wallet/server/prometheus.py index 7acde8b91..a2f82f21e 100644 --- a/lbry/wallet/server/prometheus.py +++ b/lbry/wallet/server/prometheus.py @@ -7,7 +7,7 @@ from lbry.wallet.server import util import lbry.wallet.server.version as wallet_server_version NAMESPACE = "wallet_server" - +CPU_COUNT = f"{os.cpu_count()}" VERSION_INFO = Info('build', 'Wallet server build info (e.g. version, commit hash)', namespace=NAMESPACE) VERSION_INFO.info({ 'build': BUILD, @@ -15,9 +15,10 @@ VERSION_INFO.info({ "docker_tag": DOCKER_TAG, 'version': version, "min_version": util.version_string(wallet_server_version.PROTOCOL_MIN), - "cpu_count": os.cpu_count() + "cpu_count": CPU_COUNT }) -SESSIONS_COUNT = Gauge("session_count", "Number of connected client sessions", namespace=NAMESPACE) +SESSIONS_COUNT = Gauge("session_count", "Number of connected client sessions", namespace=NAMESPACE, + labelnames=("version", )) REQUESTS_COUNT = Counter("requests_count", "Number of requests received", namespace=NAMESPACE, labelnames=("method", "version")) RESPONSE_TIMES = Histogram("response_time", "Response times", namespace=NAMESPACE, labelnames=("method", "version")) diff --git a/lbry/wallet/server/session.py b/lbry/wallet/server/session.py index 01316fcfd..dcc05f8e9 100644 --- a/lbry/wallet/server/session.py +++ b/lbry/wallet/server/session.py @@ -673,7 +673,7 @@ class SessionBase(RPCSession): context = {'conn_id': f'{self.session_id}'} self.logger = util.ConnectionLogger(self.logger, context) self.group = self.session_mgr.add_session(self) - SESSIONS_COUNT.inc() + SESSIONS_COUNT.labels(version=self.client_version).inc() peer_addr_str = self.peer_address_str() self.logger.info(f'{self.kind} {peer_addr_str}, ' f'{self.session_mgr.session_count():,d} total') @@ -682,7 +682,7 @@ class SessionBase(RPCSession): """Handle client disconnection.""" super().connection_lost(exc) self.session_mgr.remove_session(self) - SESSIONS_COUNT.dec() + SESSIONS_COUNT.labels(version=self.client_version).dec() msg = '' if not self._can_send.is_set(): msg += ' whilst paused' @@ -1428,7 +1428,10 @@ class LBRYElectrumX(SessionBase): self.close_after_send = True raise RPCError(BAD_REQUEST, f'unsupported client: {client_name}') - self.client_version = client_name[:17] + if self.client_version != client_name[:17]: + SESSIONS_COUNT.labels(version=self.client_version).dec() + self.client_version = client_name[:17] + SESSIONS_COUNT.labels(version=self.client_version).inc() CLIENT_VERSIONS.labels(version=self.client_version).inc() # Find the highest common protocol version. Disconnect if