Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(518): Label connected clients metric by database #523

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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