Skip to content

Commit

Permalink
feat: add metric for successful heartbeat notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Apr 16, 2024
1 parent ccb809f commit 9ebe037
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub struct Metrics {
/// Number of successfully sent visible notifications.
pub direct_notifications_total: Counter,

/// Number of successfully sent heartbeat notifications.
pub heartbeat_notifications_total: Counter,

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

let heartbeat_notifications_total = Counter::default();
registry.register(
"heartbeat_notifications",
"Number of heartbeat notifications",
heartbeat_notifications_total.clone(),
);

let heartbeat_token_count = Gauge::<i64, AtomicI64>::default();
registry.register(
"heartbeat_token_count",
Expand All @@ -46,6 +56,7 @@ impl Metrics {
Self {
registry,
direct_notifications_total,
heartbeat_notifications_total,
heartbeat_token_count,
}
}
Expand All @@ -55,6 +66,11 @@ impl Metrics {
self.direct_notifications_total.inc();
}

/// Counts heartbeat notification.
pub fn inc_heartbeat_notification(&self) {
self.heartbeat_notifications_total.inc();
}

/// Sets number of tokens registered for heartbeat notifications.
pub fn set_heartbeat_token_count(&self, value: usize) {
self.heartbeat_token_count.set(value as i64);
Expand Down
1 change: 1 addition & 0 deletions src/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async fn wakeup(
Ok(res) => match res.code {
200 => {
info!("delivered notification for {}", device_token);
metrics.inc_heartbeat_notification();
}
_ => {
warn!("unexpected status: {:?}", res);
Expand Down

0 comments on commit 9ebe037

Please sign in to comment.