Skip to content

Commit 4b3be1f

Browse files
fix(518): Label connected clients metric by database (#523)
Fixes #518.
1 parent 593702c commit 4b3be1f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

crates/core/src/client/client_connection.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ impl ClientConnection {
113113
// Buffer up to 64 client messages
114114
let (sendtx, sendrx) = mpsc::channel::<DataMessage>(64);
115115

116+
let db = module.info().address;
117+
116118
let sender = ClientConnectionSender { id, protocol, sendtx };
117119
let this = Self {
118120
sender,
@@ -121,7 +123,7 @@ impl ClientConnection {
121123
};
122124

123125
let actor_fut = actor(this.clone(), sendrx);
124-
let gauge_guard = WORKER_METRICS.connected_clients.inc_scope();
126+
let gauge_guard = WORKER_METRICS.connected_clients.with_label_values(&db).inc_scope();
125127
tokio::spawn(actor_fut.map(|()| drop(gauge_guard)));
126128

127129
Ok(this)

crates/core/src/worker_metrics/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use crate::util::typed_prometheus::metrics_group;
22
use once_cell::sync::Lazy;
3-
use prometheus::{Gauge, GaugeVec, HistogramVec, IntCounterVec, IntGauge, IntGaugeVec};
3+
use prometheus::{Gauge, GaugeVec, HistogramVec, IntCounterVec, IntGaugeVec};
44
use spacetimedb_lib::{Address, Hash, Identity};
55

66
metrics_group!(
77
pub struct WorkerMetrics {
88
#[name = spacetime_worker_connected_clients]
99
#[help = "Number of clients connected to the worker."]
10-
pub connected_clients: IntGauge,
10+
#[labels(database_address: Address)]
11+
pub connected_clients: IntGaugeVec,
1112

1213
#[name = spacetime_websocket_requests]
1314
#[help = "Number of websocket request messages"]

0 commit comments

Comments
 (0)