Skip to content

Commit

Permalink
re-use space metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
archeoss committed Jan 31, 2024
1 parent baeb407 commit e9a21cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions bob/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ async fn get_space_info<A: Authenticator>(

Ok(Json(SpaceInfo {
total_space: Space {
total_disk_space_bytes: disk_metrics.total_space,
used_disk_space_bytes: disk_metrics.used_space,
free_disk_space_bytes: disk_metrics.free_space,
total_disk_space_bytes: disk_metrics.total.total_space,
used_disk_space_bytes: disk_metrics.total.used_space,
free_disk_space_bytes: disk_metrics.total.free_space,
},
occupied_disk_space_bytes: occupied_disk_space_by_disk.values().sum(),
occupied_disk_space_by_disk,
Expand Down
13 changes: 9 additions & 4 deletions bob/src/hw_metrics_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const DISK_STAT_FILE: &str = "/proc/diskstats";

#[derive(Debug, Clone)]
pub(crate) struct DiskSpaceMetrics {
pub(crate) total_space: u64,
pub(crate) used_space: u64,
pub(crate) free_space: u64,
pub(crate) total: SpaceMetrics,
pub(crate) per_disk: HashMap<PathBuf, SpaceMetrics>
}

Expand Down Expand Up @@ -145,7 +143,14 @@ impl HWMetricsCollector {
gauge!(TOTAL_SPACE, bytes_to_mb(total_space) as f64);
gauge!(USED_SPACE, bytes_to_mb(used_space) as f64);
gauge!(FREE_SPACE, bytes_to_mb(free_space) as f64);
DiskSpaceMetrics { total_space, used_space, free_space, per_disk: disks_metrics }
DiskSpaceMetrics {
total: SpaceMetrics {
total_space,
used_space,
free_space,
},
per_disk: disks_metrics,
}
}

fn to_cpath(path: &Path) -> Vec<u8> {
Expand Down

0 comments on commit e9a21cf

Please sign in to comment.