Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

GH-2298 - File used percentage slightly off #2302

Merged
merged 8 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions iml-gui/crate/src/components/chart/fs_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg, GMsg>)
let result: &InfluxResult = &influx_data.results[0];

if let Some(series) = &(*result).series {
let bytes_total = series[0].values[0].1;
let bytes_free = series[0].values[0].2;
let bytes_avail = series[0].values[0].3;
let bytes_used = bytes_total - bytes_free;
let bytes_total: f64 = series[0].values[0].1;
let bytes_free: f64 = series[0].values[0].2;
let bytes_avail: f64 = series[0].values[0].3;
let bytes_used: f64 = bytes_total - bytes_free;

model.metric_data = Some(FsUsage {
bytes_used,
bytes_avail,
bytes_total,
});

model.percent_used = bytes_used / bytes_total;
model.percent_used = (bytes_used / (bytes_used + bytes_avail) * 100.0f64).ceil();
}
}
Err(e) => {
Expand Down
6 changes: 3 additions & 3 deletions iml-gui/crate/src/components/progress_circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn used_to_color(used: f64) -> &'static str {
if used.is_nan() {
C.text_gray_500
} else {
match (used.round() as u64) * 100 {
match used.round() as u64 {
75..=100 => C.text_red_500,
50..=74 => C.text_yellow_500,
0..=49 => C.text_green_500,
Expand All @@ -24,7 +24,7 @@ pub fn used_to_color(used: f64) -> &'static str {
pub fn view<'a, T>(x: impl Into<Option<(f64, &'a str)>>) -> Node<T> {
match x.into() {
Some((used, color)) => {
let stroke_length = (1.0 - used) * CIRCUMFERENCE;
let stroke_length = (100.0f64 - used) / 100.0f64 * CIRCUMFERENCE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: f64 is unnecessary when using a decimal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I just thought I would be explicit :)


svg![
class![C.stroke_current, C.fill_current],
Expand Down Expand Up @@ -80,7 +80,7 @@ pub fn view<'a, T>(x: impl Into<Option<(f64, &'a str)>>) -> Node<T> {
At::DominantBaseline => "central",
At::TextAnchor => "middle"
},
tspan![format!("{}", (100.0 * used) as u16)],
tspan![format!("{}", used as u16)],
tspan![class![C.text_gray_400], "%"]
]
],
Expand Down
4 changes: 2 additions & 2 deletions iml-gui/crate/src/page/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ pub(crate) fn space_used_view<T>(
let free = free.into()?;
let avail = avail.into()?;
let used = total.saturating_sub(free) as f64;
let pct = used / total as f64;
let pct = (used / (used as f64 + avail as f64) * 100.0f64).ceil();

Some(span![
class![C.whitespace_no_wrap],
Expand All @@ -461,7 +461,7 @@ fn files_created_view<T>(free: impl Into<Option<u64>>, total: impl Into<Option<u
.and_then(|total| {
let free = free.into()?;
let used = total.saturating_sub(free) as f64;
let pct = used / total as f64;
let pct = (used / total as f64) * 100.0f64;

Some(span![
class![C.whitespace_no_wrap],
Expand Down
10 changes: 6 additions & 4 deletions iml-services/iml-snapshot/src/retention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ async fn get_stats_from_influx(
if nodes.is_empty() {
return Ok(None);
} else {
let bytes_avail = nodes[0].bytes_avail;
let bytes_total = nodes[0].bytes_total;
let bytes_free = nodes[0].bytes_free;
let bytes_used = bytes_total - bytes_free;

return Ok(Some((bytes_total, bytes_free, bytes_used)));
return Ok(Some((bytes_avail, bytes_free, bytes_used)));
}
}

Expand Down Expand Up @@ -131,14 +132,15 @@ pub async fn process_retention(
for fs_name in filesystems {
let stats = get_stats_from_influx(&fs_name, &influx_client).await?;

if let Some((bytes_total, bytes_free, bytes_used)) = stats {
if let Some((bytes_avail, bytes_free, bytes_used)) = stats {
tracing::debug!(
"stats values: {}, {}, {}",
bytes_total,
bytes_avail,
bytes_free,
bytes_used
);
let percent_used = (bytes_used as f64 / bytes_total as f64) as f64 * 100.0f64;
let percent_used =
(bytes_used as f64 / (bytes_used as f64 + bytes_avail as f64)) as f64 * 100.0f64;
let percent_free = 100.0f64 - percent_used;

tracing::debug!(
Expand Down