diff options
author | Alex Auvolat <alex@adnab.me> | 2024-02-20 11:35:18 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2024-02-20 13:50:45 +0100 |
commit | 00d479358d31b445bfbe6d7ee3c37520be7e6d85 (patch) | |
tree | 8bd34b29b869467a39a30c1a2115523d7a4bce31 /src/rpc/system_metrics.rs | |
parent | 0b9859befa80f0524da2c2ad121105e6263f8a33 (diff) | |
download | garage-00d479358d31b445bfbe6d7ee3c37520be7e6d85.tar.gz garage-00d479358d31b445bfbe6d7ee3c37520be7e6d85.zip |
[peer-metrics] refactor/simplify SystemMetrics
Diffstat (limited to 'src/rpc/system_metrics.rs')
-rw-r--r-- | src/rpc/system_metrics.rs | 52 |
1 files changed, 20 insertions, 32 deletions
diff --git a/src/rpc/system_metrics.rs b/src/rpc/system_metrics.rs index af81b71f..7b390c25 100644 --- a/src/rpc/system_metrics.rs +++ b/src/rpc/system_metrics.rs @@ -1,31 +1,22 @@ -use std::sync::atomic::{AtomicU64, Ordering}; -use std::sync::Arc; +use std::sync::{Arc, RwLock}; use opentelemetry::{global, metrics::*, KeyValue}; +use crate::system::NodeStatus; + /// TableMetrics reference all counter used for metrics pub struct SystemMetrics { pub(crate) _garage_build_info: ValueObserver<u64>, pub(crate) _replication_factor: ValueObserver<u64>, pub(crate) _disk_avail: ValueObserver<u64>, pub(crate) _disk_total: ValueObserver<u64>, - pub(crate) values: Arc<SystemMetricsValues>, -} - -#[derive(Default)] -pub struct SystemMetricsValues { - pub(crate) data_disk_total: AtomicU64, - pub(crate) data_disk_avail: AtomicU64, - pub(crate) meta_disk_total: AtomicU64, - pub(crate) meta_disk_avail: AtomicU64, } impl SystemMetrics { - pub fn new(replication_factor: usize) -> Self { + pub fn new(replication_factor: usize, local_status: Arc<RwLock<NodeStatus>>) -> Self { let meter = global::meter("garage_system"); - let values = Arc::new(SystemMetricsValues::default()); - let values1 = values.clone(); - let values2 = values.clone(); + let st1 = local_status.clone(); + let st2 = local_status.clone(); Self { _garage_build_info: meter .u64_value_observer("garage_build_info", move |observer| { @@ -47,31 +38,28 @@ impl SystemMetrics { .init(), _disk_avail: meter .u64_value_observer("garage_local_disk_avail", move |observer| { - match values1.data_disk_avail.load(Ordering::Relaxed) { - 0 => (), - x => observer.observe(x, &[KeyValue::new("volume", "data")]), - }; - match values1.meta_disk_avail.load(Ordering::Relaxed) { - 0 => (), - x => observer.observe(x, &[KeyValue::new("volume", "metadata")]), - }; + let st = st1.read().unwrap(); + if let Some((avail, _total)) = st.data_disk_avail { + observer.observe(avail, &[KeyValue::new("volume", "data")]); + } + if let Some((avail, _total)) = st.meta_disk_avail { + observer.observe(avail, &[KeyValue::new("volume", "metadata")]); + } }) .with_description("Garage available disk space on each node") .init(), _disk_total: meter .u64_value_observer("garage_local_disk_total", move |observer| { - match values2.data_disk_total.load(Ordering::Relaxed) { - 0 => (), - x => observer.observe(x, &[KeyValue::new("volume", "data")]), - }; - match values2.meta_disk_total.load(Ordering::Relaxed) { - 0 => (), - x => observer.observe(x, &[KeyValue::new("volume", "metadata")]), - }; + let st = st2.read().unwrap(); + if let Some((_avail, total)) = st.data_disk_avail { + observer.observe(total, &[KeyValue::new("volume", "data")]); + } + if let Some((_avail, total)) = st.meta_disk_avail { + observer.observe(total, &[KeyValue::new("volume", "metadata")]); + } }) .with_description("Garage total disk space on each node") .init(), - values, } } } |