Skip to content

Commit

Permalink
Count heartbeat registrations
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Apr 17, 2024
1 parent 4739f3e commit f79a513
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub struct Metrics {
/// Number of successfully sent heartbeat notifications.
pub heartbeat_notifications_total: Counter,

/// Number of heartbeat token registrations.
pub heartbeat_registrations_total: Counter,

/// Number of tokens registered for heartbeat notifications.
pub heartbeat_token_count: Gauge<i64, AtomicI64>,
}
Expand All @@ -46,6 +49,13 @@ impl Metrics {
heartbeat_notifications_total.clone(),
);

let heartbeat_registrations_total = Counter::default();
registry.register(
"heartbeat_registrations",
"Number of heartbeat registrations",
heartbeat_registrations_total.clone(),
);

let heartbeat_token_count = Gauge::<i64, AtomicI64>::default();
registry.register(
"heartbeat_token_count",
Expand All @@ -57,6 +67,7 @@ impl Metrics {
registry,
direct_notifications_total,
heartbeat_notifications_total,
heartbeat_registrations_total,
heartbeat_token_count,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ async fn register_device(mut req: tide::Request<State>) -> tide::Result<tide::Re
db.insert(query.token.as_bytes(), vec![1])?;
db.flush_async().await?;

req.state().metrics().heartbeat_registrations_total.inc();

Ok(tide::Response::new(tide::StatusCode::Ok))
}

Expand Down

0 comments on commit f79a513

Please sign in to comment.