2024-02-20 10:35:18 +00:00
|
|
|
use std::sync::{Arc, RwLock};
|
2023-01-26 14:30:36 +00:00
|
|
|
|
2023-01-09 17:13:41 +00:00
|
|
|
use opentelemetry::{global, metrics::*, KeyValue};
|
|
|
|
|
2024-02-20 10:35:18 +00:00
|
|
|
use crate::system::NodeStatus;
|
|
|
|
|
2023-01-09 17:13:41 +00:00
|
|
|
/// TableMetrics reference all counter used for metrics
|
|
|
|
pub struct SystemMetrics {
|
|
|
|
pub(crate) _garage_build_info: ValueObserver<u64>,
|
|
|
|
pub(crate) _replication_factor: ValueObserver<u64>,
|
2023-01-26 14:30:36 +00:00
|
|
|
pub(crate) _disk_avail: ValueObserver<u64>,
|
|
|
|
pub(crate) _disk_total: ValueObserver<u64>,
|
2023-01-09 17:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SystemMetrics {
|
2024-02-20 10:35:18 +00:00
|
|
|
pub fn new(replication_factor: usize, local_status: Arc<RwLock<NodeStatus>>) -> Self {
|
2023-01-09 17:13:41 +00:00
|
|
|
let meter = global::meter("garage_system");
|
2024-02-20 10:35:18 +00:00
|
|
|
let st1 = local_status.clone();
|
|
|
|
let st2 = local_status.clone();
|
2023-01-09 17:13:41 +00:00
|
|
|
Self {
|
|
|
|
_garage_build_info: meter
|
|
|
|
.u64_value_observer("garage_build_info", move |observer| {
|
|
|
|
observer.observe(
|
|
|
|
1,
|
2023-03-10 11:40:58 +00:00
|
|
|
&[
|
|
|
|
KeyValue::new("rustversion", garage_util::version::rust_version()),
|
|
|
|
KeyValue::new("version", garage_util::version::garage_version()),
|
|
|
|
],
|
2023-01-09 17:13:41 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.with_description("Garage build info")
|
|
|
|
.init(),
|
|
|
|
_replication_factor: meter
|
|
|
|
.u64_value_observer("garage_replication_factor", move |observer| {
|
|
|
|
observer.observe(replication_factor as u64, &[])
|
|
|
|
})
|
|
|
|
.with_description("Garage replication factor setting")
|
|
|
|
.init(),
|
2023-01-26 14:30:36 +00:00
|
|
|
_disk_avail: meter
|
|
|
|
.u64_value_observer("garage_local_disk_avail", move |observer| {
|
2024-02-20 10:35:18 +00:00
|
|
|
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")]);
|
|
|
|
}
|
2023-01-26 14:30:36 +00:00
|
|
|
})
|
|
|
|
.with_description("Garage available disk space on each node")
|
|
|
|
.init(),
|
|
|
|
_disk_total: meter
|
|
|
|
.u64_value_observer("garage_local_disk_total", move |observer| {
|
2024-02-20 10:35:18 +00:00
|
|
|
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")]);
|
|
|
|
}
|
2023-01-26 14:30:36 +00:00
|
|
|
})
|
|
|
|
.with_description("Garage total disk space on each node")
|
|
|
|
.init(),
|
2023-01-09 17:13:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|