Skip to content

Commit

Permalink
feat(metrics): Add disk used ratio metric
Browse files Browse the repository at this point in the history
  • Loading branch information
zuston committed Dec 5, 2024
1 parent c85b9fc commit c651ed5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
19 changes: 16 additions & 3 deletions src/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use crate::runtime::manager::RuntimeManager;
use log::{error, info};
use once_cell::sync::Lazy;
use prometheus::{
histogram_opts, labels, register_histogram_vec_with_registry, register_int_counter_vec,
register_int_gauge_vec, Histogram, HistogramOpts, HistogramVec, IntCounter, IntCounterVec,
IntGauge, IntGaugeVec, Registry,
histogram_opts, labels, register_gauge_vec, register_histogram_vec_with_registry,
register_int_counter_vec, register_int_gauge_vec, GaugeVec, Histogram, HistogramOpts,
HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Registry,
};
use std::time::Duration;

Expand Down Expand Up @@ -420,6 +420,15 @@ pub static GAUGE_LOCAL_DISK_USED: Lazy<IntGaugeVec> = Lazy::new(|| {
.unwrap()
});

pub static GAUGE_LOCAL_DISK_USED_RATIO: Lazy<GaugeVec> = Lazy::new(|| {
register_gauge_vec!(
"local_disk_used_ratio",
"local disk used ratio for root path",
&["root"]
)
.unwrap()
});

pub static GAUGE_LOCAL_DISK_IS_HEALTHY: Lazy<IntGaugeVec> = Lazy::new(|| {
register_int_gauge_vec!(
"local_disk_is_healthy",
Expand Down Expand Up @@ -660,6 +669,10 @@ fn register_custom_metrics() {
.register(Box::new(GAUGE_LOCAL_DISK_USED.clone()))
.expect("");

REGISTRY
.register(Box::new(GAUGE_LOCAL_DISK_USED_RATIO.clone()))
.expect("");

REGISTRY
.register(Box::new(GAUGE_LOCAL_DISK_IS_HEALTHY.clone()))
.expect("");
Expand Down
11 changes: 7 additions & 4 deletions src/store/local/delegator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use crate::await_tree::AWAIT_TREE_REGISTRY;
use crate::config::LocalfileStoreConfig;
use crate::metric::{
GAUGE_LOCAL_DISK_CAPACITY, GAUGE_LOCAL_DISK_IS_HEALTHY, GAUGE_LOCAL_DISK_USED,
LOCALFILE_DISK_APPEND_OPERATION_DURATION, LOCALFILE_DISK_DELETE_OPERATION_DURATION,
LOCALFILE_DISK_READ_OPERATION_DURATION, TOTAL_LOCAL_DISK_APPEND_OPERATION_BYTES_COUNTER,
TOTAL_LOCAL_DISK_APPEND_OPERATION_COUNTER, TOTAL_LOCAL_DISK_READ_OPERATION_BYTES_COUNTER,
TOTAL_LOCAL_DISK_READ_OPERATION_COUNTER,
GAUGE_LOCAL_DISK_USED_RATIO, LOCALFILE_DISK_APPEND_OPERATION_DURATION,
LOCALFILE_DISK_DELETE_OPERATION_DURATION, LOCALFILE_DISK_READ_OPERATION_DURATION,
TOTAL_LOCAL_DISK_APPEND_OPERATION_BYTES_COUNTER, TOTAL_LOCAL_DISK_APPEND_OPERATION_COUNTER,
TOTAL_LOCAL_DISK_READ_OPERATION_BYTES_COUNTER, TOTAL_LOCAL_DISK_READ_OPERATION_COUNTER,
};
use crate::readable_size::ReadableSize;
use crate::runtime::manager::RuntimeManager;
Expand Down Expand Up @@ -159,6 +159,9 @@ impl LocalDiskDelegator {
GAUGE_LOCAL_DISK_USED
.with_label_values(&[&self.inner.root])
.set(used as i64);
GAUGE_LOCAL_DISK_USED_RATIO
.with_label_values(&[&self.inner.root])
.set((used / capacity) as f64);

let used_ratio = used as f64 / capacity as f64;
let healthy_stat = self.is_healthy()?;
Expand Down

0 comments on commit c651ed5

Please sign in to comment.