datacake_eventual_consistency/
statistics.rs

1use std::ops::Deref;
2use std::sync::atomic::{AtomicU64, Ordering};
3use std::sync::Arc;
4
5pub type Counter = AtomicU64;
6
7#[derive(Debug, Clone, Default)]
8/// Live metrics around the cluster system.
9pub struct SystemStatistics(Arc<SystemStatisticsInner>);
10
11impl Deref for SystemStatistics {
12    type Target = SystemStatisticsInner;
13
14    fn deref(&self) -> &Self::Target {
15        &self.0
16    }
17}
18
19#[derive(Debug, Default)]
20pub struct SystemStatisticsInner {
21    /// The number of synchronisation tasks that are currently running concurrently.
22    pub(crate) num_ongoing_sync_tasks: Counter,
23    /// The number of synchronisation tasks that took longer than the selected timeout.
24    pub(crate) num_slow_sync_tasks: Counter,
25    /// The number of sync tasks that failed to complete due to an error.
26    pub(crate) num_failed_sync_tasks: Counter,
27    /// The number of times the node has observed a remote keyspace change.
28    pub(crate) num_keyspace_changes: Counter,
29}
30
31impl SystemStatisticsInner {
32    /// The number of synchronisation tasks that are currently running concurrently.
33    pub fn num_ongoing_sync_tasks(&self) -> u64 {
34        self.num_ongoing_sync_tasks.load(Ordering::Relaxed)
35    }
36
37    /// The number of synchronisation tasks that took longer than the selected timeout.
38    pub fn num_slow_sync_tasks(&self) -> u64 {
39        self.num_slow_sync_tasks.load(Ordering::Relaxed)
40    }
41
42    /// The number of sync tasks that failed to complete due to an error.
43    pub fn num_failed_sync_tasks(&self) -> u64 {
44        self.num_failed_sync_tasks.load(Ordering::Relaxed)
45    }
46
47    /// The number of times the node has observed a remote keyspace change.
48    pub fn num_keyspace_changes(&self) -> u64 {
49        self.num_keyspace_changes.load(Ordering::Relaxed)
50    }
51}