-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[823] add detailed disk metrics #827
base: master
Are you sure you want to change the base?
Changes from 20 commits
f19516e
2b35c14
34141fc
b43ee7c
5ec7e17
188fbf5
475299a
5035637
f9ef9e9
c91108d
462d9f7
4dece52
b1aef5c
a3a7393
65a3c1a
582b617
abb9358
5c9c28f
baeb407
e9a21cf
44f7db8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use crate::{ | ||
build_info::BuildInfo, hw_metrics_collector::DiskSpaceMetrics, server::Server as BobServer, | ||
build_info::BuildInfo, server::Server as BobServer, | ||
}; | ||
use axum::{ | ||
body::{self, BoxBody}, | ||
|
@@ -20,7 +20,7 @@ use bob_backend::pearl::{Group as PearlGroup, Holder, NoopHooks}; | |
use bob_common::{ | ||
configs::node::TLSConfig, | ||
data::{BobData, BobKey, BobMeta, BOB_KEY_SIZE}, | ||
core_types::{VDisk as DataVDisk, NodeDisk}, | ||
core_types::{VDisk as DataVDisk, NodeDisk, DiskName}, | ||
operation_options::{BobPutOptions, BobGetOptions, BobDeleteOptions}, | ||
error::Error as BobError, | ||
}; | ||
|
@@ -145,12 +145,25 @@ pub(crate) struct NodeConfiguration { | |
} | ||
|
||
#[derive(Debug, Serialize)] | ||
pub(crate) struct SpaceInfo { | ||
struct Space { | ||
total_disk_space_bytes: u64, | ||
free_disk_space_bytes: u64, | ||
used_disk_space_bytes: u64, | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
pub(crate) struct SpaceInfo { | ||
#[serde(flatten)] | ||
total_space: Space, | ||
|
||
/// Total occupied disk space by Bob | ||
occupied_disk_space_bytes: u64, | ||
occupied_disk_space_by_disk: HashMap<String, u64>, | ||
|
||
/// Key - Bob disk name | ||
occupied_disk_space_by_disk: HashMap<DiskName, u64>, | ||
|
||
/// Key - Mount point or Bob disk name if no mount point was found | ||
disk_space_by_disk: HashMap<String, Space>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just thought that it would be better to use disk name as the key (on Linux it is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, it would be better to do it later in another request. Right now, mount point would be enough here |
||
} | ||
|
||
async fn tls_server(tls_config: &TLSConfig, addr: SocketAddr) -> AxumServer<RustlsAcceptor> { | ||
|
@@ -313,31 +326,39 @@ async fn status<A: Authenticator>(bob: Extension<BobServer<A>>) -> Json<Node> { | |
async fn get_space_info<A: Authenticator>( | ||
bob: Extension<BobServer<A>>, | ||
) -> Result<Json<SpaceInfo>, StatusExt> { | ||
let DiskSpaceMetrics { | ||
total_space, | ||
used_space, | ||
free_space, | ||
} = bob.grinder().hw_counter().update_space_metrics(); | ||
|
||
let disk_metrics = bob.grinder().hw_counter().update_space_metrics(); | ||
let backend = bob.grinder().backend().inner(); | ||
let (dcs, adc) = backend | ||
.disk_controllers() | ||
.ok_or_else(not_acceptable_backend)?; | ||
let mut map = HashMap::new(); | ||
for dc in dcs.iter() { | ||
map.insert(dc.disk().name().to_string(), dc.disk_used().await); | ||
} | ||
|
||
let mut occupied_disk_space_by_disk: HashMap<DiskName, u64> = futures::future::join_all( | ||
dcs.iter().map(|dc| async { ( dc.disk().name().clone(), dc.disk_used().await ) }) | ||
).await.into_iter().collect(); | ||
let adc_space = adc.disk_used().await; | ||
map.entry(adc.disk().name().to_string()) | ||
.and_modify(|s| *s = *s + adc_space) | ||
|
||
let disk_space_by_disk = disk_metrics.per_disk.into_iter().map(|(mount_point, disk)| ( | ||
mount_point.to_string_lossy().to_string(), | ||
Space { | ||
total_disk_space_bytes: disk.total_space, | ||
free_disk_space_bytes: disk.free_space, | ||
used_disk_space_bytes: disk.used_space | ||
} | ||
)).collect(); | ||
|
||
occupied_disk_space_by_disk.entry(adc.disk().name().clone()) | ||
.and_modify(|s| *s += adc_space) | ||
.or_insert(adc_space); | ||
|
||
Ok(Json(SpaceInfo { | ||
total_disk_space_bytes: total_space, | ||
used_disk_space_bytes: used_space, | ||
free_disk_space_bytes: free_space, | ||
occupied_disk_space_bytes: map.values().sum(), | ||
occupied_disk_space_by_disk: map, | ||
total_space: 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, | ||
disk_space_by_disk, | ||
})) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update openapi in
config-examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to integrate utoipa for openapi auto-gen at some point