Skip to content

Commit

Permalink
fix(518): Label connected clients metric by database
Browse files Browse the repository at this point in the history
Fixes #518.
  • Loading branch information
joshua-spacetime committed Nov 3, 2023
1 parent 593702c commit 51a8e1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion crates/core/src/client/client_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ impl ClientConnection {
// Buffer up to 64 client messages
let (sendtx, sendrx) = mpsc::channel::<DataMessage>(64);

let db = module.info().address;

let sender = ClientConnectionSender { id, protocol, sendtx };
let this = Self {
sender,
Expand All @@ -121,7 +123,7 @@ impl ClientConnection {
};

let actor_fut = actor(this.clone(), sendrx);
let gauge_guard = WORKER_METRICS.connected_clients.inc_scope();
let gauge_guard = WORKER_METRICS.connected_clients.with_label_values(&db).inc_scope();
tokio::spawn(actor_fut.map(|()| drop(gauge_guard)));

Ok(this)
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/worker_metrics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::util::typed_prometheus::metrics_group;
use once_cell::sync::Lazy;
use prometheus::{Gauge, GaugeVec, HistogramVec, IntCounterVec, IntGauge, IntGaugeVec};
use prometheus::{Gauge, GaugeVec, HistogramVec, IntCounterVec, IntGaugeVec};
use spacetimedb_lib::{Address, Hash, Identity};

metrics_group!(
pub struct WorkerMetrics {
#[name = spacetime_worker_connected_clients]
#[help = "Number of clients connected to the worker."]
pub connected_clients: IntGauge,
#[labels(database_address: Address)]
pub connected_clients: IntGaugeVec,

#[name = spacetime_websocket_requests]
#[help = "Number of websocket request messages"]
Expand Down

0 comments on commit 51a8e1b

Please sign in to comment.