1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-08-09 04:22:45 +03:00

Add metric which tracks the maximum number of connections to the database.

This commit is contained in:
Quentin Gliech
2023-07-18 17:19:25 +02:00
parent ca8c05ef8b
commit 016c65c9f8

View File

@@ -65,15 +65,23 @@ impl AppState {
let usage = meter
.i64_observable_up_down_counter("db.connections.usage")
.with_description("The number of connections that are currently in `state` described by the state attribute.")
.with_unit(Unit::new("connection"))
.with_unit(Unit::new("{connection}"))
.init();
let max = meter
.i64_observable_up_down_counter("db.connections.max")
.with_description("The maximum number of open connections allowed.")
.with_unit(Unit::new("{connection}"))
.init();
// Observe the number of active and idle connections in the pool
meter.register_callback(move |cx| {
let idle = u32::try_from(pool.num_idle()).unwrap_or(u32::MAX);
let used = pool.size() - idle;
let max_conn = pool.options().get_max_connections();
usage.observe(cx, i64::from(idle), &[KeyValue::new("state", "idle")]);
usage.observe(cx, i64::from(used), &[KeyValue::new("state", "used")]);
max.observe(cx, i64::from(max_conn), &[]);
})?;
// Track the connection acquisition time