diff --git a/baseplate/clients/memcache/__init__.py b/baseplate/clients/memcache/__init__.py index 54fd13dbb..38602cbd9 100644 --- a/baseplate/clients/memcache/__init__.py +++ b/baseplate/clients/memcache/__init__.py @@ -133,31 +133,31 @@ class MemcacheContextFactory(ContextFactory): PROM_PREFIX = "bp_memcached_pool" PROM_LABELS = ["pool"] - promTotalConnections = Gauge( + prom_total_connections = Gauge( f"{PROM_PREFIX}_size", "Maximum size of this pool", PROM_LABELS, ) - promUsedConnections = Gauge( + prom_used_connections = Gauge( f"{PROM_PREFIX}_in_use", "Number of connections in this pool currently in use", PROM_LABELS, ) - promFreeConnections = Gauge( + prom_free_connections = Gauge( f"{PROM_PREFIX}_free", "Number of free connections in this pool", PROM_LABELS, ) - def __init__(self, pooled_client: PooledClient, name: str = "memcache"): + def __init__(self, pooled_client: PooledClient, name: str = "default"): self.pooled_client = pooled_client pool = self.pooled_client.client_pool - self.promTotalConnections.labels(name).set_function(lambda: pool.max_size) - self.promFreeConnections.labels(name).set_function(lambda: len(pool.free)) - self.promUsedConnections.labels(name).set_function(lambda: len(pool.used)) + self.prom_total_connections.labels(name).set_function(lambda: pool.max_size) + self.prom_free_connections.labels(name).set_function(lambda: len(pool.free)) + self.prom_used_connections.labels(name).set_function(lambda: len(pool.used)) def report_memcache_runtime_metrics(self, batch: metrics.Client) -> None: pool = self.pooled_client.client_pool diff --git a/baseplate/clients/redis.py b/baseplate/clients/redis.py index f760a48ae..26657eb18 100644 --- a/baseplate/clients/redis.py +++ b/baseplate/clients/redis.py @@ -97,18 +97,18 @@ class RedisContextFactory(ContextFactory): PROM_PREFIX = "bp_redis_pool" PROM_LABELS = ["pool"] - totalConnections = Gauge( + total_connections = Gauge( f"{PROM_PREFIX}_connections", "Number of connections in this redisbp pool", PROM_LABELS, ) - idleConnections = Gauge( - f"{PROM_PREFIX}_idle_connections", + idle_connections = Gauge( + f"{PROM_PREFIX}_connections_idle", "Number of idle connections in this redisbp pool", PROM_LABELS, ) - openConnections = Gauge( - f"{PROM_PREFIX}_open_connections", + open_connections = Gauge( + f"{PROM_PREFIX}_connections_open", "Number of open connections in this redisbp pool", PROM_LABELS, ) @@ -117,9 +117,11 @@ def __init__(self, connection_pool: redis.ConnectionPool, name: str = "redis"): self.connection_pool = connection_pool if isinstance(connection_pool, redis.BlockingConnectionPool): - self.totalConnections.labels(name).set_function(lambda: connection_pool.max_connections) - self.idleConnections.labels(name).set_function(connection_pool.pool.qsize) - self.openConnections.labels(name).set_function( + self.total_connections.labels(name).set_function( + lambda: connection_pool.max_connections + ) + self.idle_connections.labels(name).set_function(connection_pool.pool.qsize) + self.open_connections.labels(name).set_function( lambda: len(connection_pool._connections) # type: ignore ) diff --git a/baseplate/clients/sqlalchemy.py b/baseplate/clients/sqlalchemy.py index 1e4d7bf94..a7565bbbc 100644 --- a/baseplate/clients/sqlalchemy.py +++ b/baseplate/clients/sqlalchemy.py @@ -159,25 +159,25 @@ class SQLAlchemyEngineContextFactory(ContextFactory): PROM_PREFIX = "bp_sqlalchemy_pool" PROM_LABELS = ["pool"] - promTotalConnections = Gauge( - f"{PROM_PREFIX}_size", + prom_total_connections = Gauge( + f"{PROM_PREFIX}_connections", "Total number of connections in this pool", PROM_LABELS, ) - promCheckedInConnections = Gauge( - f"{PROM_PREFIX}_checked_in", + prom_checked_in_connections = Gauge( + f"{PROM_PREFIX}_idle", "Number of available, checked in, connections in this pool", PROM_LABELS, ) - promCheckedOutConnections = Gauge( - f"{PROM_PREFIX}_checked_out", + prom_checked_out_connections = Gauge( + f"{PROM_PREFIX}_active", "Number of connections in use, or checked out, in this pool", PROM_LABELS, ) - promOverflowConnections = Gauge( + prom_overflow_connections = Gauge( f"{PROM_PREFIX}_overflow_connections", "Number of connections over the desired size of this pool", PROM_LABELS, @@ -191,10 +191,10 @@ def __init__(self, engine: Engine, name: str = "sqlalchemy"): pool = self.engine.pool if isinstance(pool, QueuePool): - self.promTotalConnections.labels(name).set_function(pool.size) - self.promCheckedInConnections.labels(name).set_function(pool.checkedin) - self.promCheckedOutConnections.labels(name).set_function(pool.checkedout) - self.promOverflowConnections.labels(name).set_function(pool.overflow) + self.prom_total_connections.labels(name).set_function(pool.size) + self.prom_checked_in_connections.labels(name).set_function(pool.checkedin) + self.prom_checked_out_connections.labels(name).set_function(pool.checkedout) + self.prom_overflow_connections.labels(name).set_function(pool.overflow) def report_runtime_metrics(self, batch: metrics.Client) -> None: pool = self.engine.pool diff --git a/baseplate/clients/thrift.py b/baseplate/clients/thrift.py index 3e7fc2bc8..6e82b616b 100644 --- a/baseplate/clients/thrift.py +++ b/baseplate/clients/thrift.py @@ -73,13 +73,13 @@ class ThriftContextFactory(ContextFactory): PROM_PREFIX = "bp_thrift_pool" PROM_LABELS = ["client_cls"] - promTotalConnections = Gauge( + prom_total_connections = Gauge( f"{PROM_PREFIX}_size", "Number of connections in this thrift pool", PROM_LABELS, ) - promUsedConnections = Gauge( + prom_used_connections = Gauge( f"{PROM_PREFIX}_in_use", "Number of connections currently in use in this thrift pool", PROM_LABELS, @@ -99,8 +99,8 @@ def __init__(self, pool: ThriftConnectionPool, client_cls: Any): ) pool_name = type(self.client_cls).__name__ - self.promTotalConnections.labels(pool_name).set_function(lambda: self.pool.size) - self.promUsedConnections.labels(pool_name).set_function(lambda: self.pool.checkedout) + self.prom_total_connections.labels(pool_name).set_function(lambda: self.pool.size) + self.prom_used_connections.labels(pool_name).set_function(lambda: self.pool.checkedout) def report_runtime_metrics(self, batch: metrics.Client) -> None: batch.gauge("pool.size").replace(self.pool.size) diff --git a/tests/unit/clients/redis_tests.py b/tests/unit/clients/redis_tests.py index 30c1fca77..5e0cf92c1 100644 --- a/tests/unit/clients/redis_tests.py +++ b/tests/unit/clients/redis_tests.py @@ -30,7 +30,7 @@ def test_metrics(self): {"redis.url": "redis://localhost:1234/0", "redis.max_connections": max_connections} ) ) - metric = ctx.totalConnections.collect() + metric = ctx.total_connections.collect() self.assertEqual(metric[0].samples[0].value, float(max_connections)) def test_timeouts(self):