add min_version and method name to metrics

This commit is contained in:
Alex Grintsvayg 2020-01-23 12:37:13 -05:00
parent fb568768c5
commit 0732ab6ad5
No known key found for this signature in database
GPG key ID: AEB3F089F86A22B5
3 changed files with 16 additions and 6 deletions

View file

@ -1,14 +1,20 @@
from aiohttp import web
from prometheus_client import Counter, Info, generate_latest as prom_generate_latest
from lbry.wallet.server import util
from lbry import __version__ as version
from lbry.build_info import BUILD, COMMIT_HASH
from lbry.wallet.server import util
import lbry.wallet.server.version as wallet_server_version
NAMESPACE = "wallet_server"
VERSION_INFO = Info('build', 'Wallet server build info (e.g. version, commit hash)', namespace=NAMESPACE)
VERSION_INFO.info({'version': version, 'build': BUILD, "commit": COMMIT_HASH})
REQUESTS_COUNT = Counter("requests_count", "Number of requests received", namespace=NAMESPACE)
VERSION_INFO.info({
'build': BUILD,
"commit": COMMIT_HASH,
'version': version,
"min_version": util.version_string(wallet_server_version.PROTOCOL_MIN),
})
REQUESTS_COUNT = Counter("requests_count", "Number of requests received", namespace=NAMESPACE, labelnames=("method",))
class PrometheusServer:

View file

@ -28,6 +28,7 @@ from lbry.wallet.server.db import reader
from lbry.wallet.server.websocket import AdminWebSocket
from lbry.wallet.server.metrics import ServerLoadData, APICallMetrics
from lbry.wallet.server.prometheus import REQUESTS_COUNT
import lbry.wallet.server.version as VERSION
from lbry.wallet.rpc import (
RPCSession, JSONRPCAutoDetect, JSONRPCConnection,
@ -708,7 +709,7 @@ class SessionBase(RPCSession):
"""Handle an incoming request. ElectrumX doesn't receive
notifications from client sessions.
"""
REQUESTS_COUNT.inc()
REQUESTS_COUNT.labels(method=request.method).inc()
if isinstance(request, Request):
handler = self.request_handlers.get(request.method)
else:
@ -778,8 +779,8 @@ class LBRYSessionManager(SessionManager):
class LBRYElectrumX(SessionBase):
"""A TCP server that handles incoming Electrum connections."""
PROTOCOL_MIN = (0, 54, 0)
PROTOCOL_MAX = (0, 99, 0)
PROTOCOL_MIN = VERSION.PROTOCOL_MIN
PROTOCOL_MAX = VERSION.PROTOCOL_MAX
max_errors = math.inf # don't disconnect people for errors! let them happen...
session_mgr: LBRYSessionManager
version = lbry.__version__

View file

@ -0,0 +1,3 @@
# need this to avoid circular import
PROTOCOL_MIN = (0, 54, 0)
PROTOCOL_MAX = (0, 99, 0)