From 550aa7593b23bc80ae59b61570b8a3e2f93a4b4a Mon Sep 17 00:00:00 2001 From: iliajie Date: Thu, 2 Mar 2023 21:24:49 +0200 Subject: [PATCH] Fix to properly display used space (consider reserved) --- mount/linux-lib.pl | 8 ++++---- mount/mount-lib.pl | 8 ++++++-- mount/system_info.pl | 10 +++++----- system-status/system-status-lib.pl | 6 ++++-- system-status/system_info.pl | 10 +++++++--- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/mount/linux-lib.pl b/mount/linux-lib.pl index 4607ee90f..c57c7218b 100755 --- a/mount/linux-lib.pl +++ b/mount/linux-lib.pl @@ -905,8 +905,8 @@ if ($_[0] eq "proc" || $_[0] eq "swap" || &clean_language(); local $out = &backquote_command("df -k ".quotemeta($_[1]), 1); &reset_environment(); -if ($out =~ /Mounted on\n\S+\s+(\S+)\s+\S+\s+(\S+)/) { - return ($1, $2); +if ($out =~ /Mounted on\n\S+\s+(?\S+)\s+(?\S+)\s+(?\S+)\s+(?\d+)/) { + return ("$+{total}", "$+{free}", "$+{used}", "$+{percent}"); } return ( ); } @@ -919,8 +919,8 @@ if (&get_mounted($_[1], "*") < 0) { return (); } &clean_language(); local $out = &backquote_command("df -i $_[1]", 1); &reset_environment(); -if ($out =~ /Mounted on\n\S+\s+(\S+)\s+\S+\s+(\S+)/) { - return ($1, $2); +if ($out =~ /Mounted on\n\S+\s+(?\S+)\s+(?\S+)\s+(?\S+)\s+(?\d+)/) { + return ("$+{total}", "$+{free}", "$+{used}", "$+{percent}"); } return ( ); } diff --git a/mount/mount-lib.pl b/mount/mount-lib.pl index 41882c66a..797edd9d8 100755 --- a/mount/mount-lib.pl +++ b/mount/mount-lib.pl @@ -365,7 +365,7 @@ foreach my $m (@mounted) { ($t, $f) = @$zp; } else { - ($t, $f) = &disk_space($m->[2], $m->[0]); + ($t, $f, $u, $p) = &disk_space($m->[2], $m->[0]); } if (($m->[2] eq "simfs" || $m->[2] eq "vzfs" || $m->[0] eq "/dev/vzfs" || @@ -378,12 +378,16 @@ foreach my $m (@mounted) { $free += $f*1024; my ($it, $if); if (defined(&inode_space)) { - ($it, $if) = &inode_space($m->[2], $m->[0]); + ($it, $if, $iu, $ip) = &inode_space($m->[2], $m->[0]); } push(@fs, { 'total' => $t*1024, 'free' => $f*1024, + 'used' => $u*1024, + 'used_percent' => $p, 'itotal' => $it, 'ifree' => $if, + 'iused' => $iu, + 'iused_percent' => $ip, 'dir' => $m->[0], 'device' => $m->[1], 'type' => $m->[2] }); diff --git a/mount/system_info.pl b/mount/system_info.pl index b0918b4fe..a4dd2a168 100644 --- a/mount/system_info.pl +++ b/mount/system_info.pl @@ -32,9 +32,9 @@ sub list_system_info my $total_nice = &nice_size($total); my $free = $disk->{'free'}; my $ifree = $disk->{'ifree'}; - my $used = &nice_size($disk->{'total'} - $disk->{'free'}); - my $free_nice = &nice_size($disk->{'free'}); - my $free_percent = 100 - int(($total - $free) / $total * 100); + my $used_nice = &nice_size($disk->{'used'} // $total - $free); + my $free_nice = &nice_size($free); + my $free_percent = 100 - ($disk->{'used_percent'} // int(($total - $free) / $total * 100)); my $free_percent_html; # Inodes percent @@ -67,11 +67,11 @@ sub list_system_info if ($itotal) { $ifree_percent_html = "
".$ifree_percent_html." ($ifree inodes)
"; $itotal_full = "
$itotal inodes
"; - $iused = "
@{[$disk->{'itotal'} - $disk->{'ifree'}]} inodes
"; + $iused = "
@{[$disk->{'iused'} // $disk->{'itotal'} - $disk->{'ifree'}]} inodes
"; } $html .= &ui_columns_row([$dir, $type, $free_percent_html . " ($free_nice)$ifree_percent_html", - "$used$iused", + "$used_nice$iused", "$total_nice$itotal_full", $dev_id,]); } } diff --git a/system-status/system-status-lib.pl b/system-status/system-status-lib.pl index 054d0b7d0..b227c5612 100755 --- a/system-status/system-status-lib.pl +++ b/system-status/system-status-lib.pl @@ -179,9 +179,11 @@ if ($info->{'mem'}) { } } if ($info->{'disk_total'}) { + my $disk_used = $info->{'disk_fs'} ? + $info->{'disk_fs'}->[0]->{'used'} : undef; push(@stats, [ "diskused", - $info->{'disk_total'}-$info->{'disk_free'}, - $info->{'disk_total'} ]); + $disk_used // $info->{'disk_total'}-$info->{'disk_free'}, + $info->{'disk_total'} ]); } # Get network traffic counts since last run diff --git a/system-status/system_info.pl b/system-status/system_info.pl index 0333e5da7..fa3340b3c 100644 --- a/system-status/system_info.pl +++ b/system-status/system_info.pl @@ -237,12 +237,16 @@ if ($info->{'mem'} && &show_section('mem')) { # Disk space on local drives if ($info->{'disk_total'} && &show_section('disk')) { - my ($total, $free) = ($info->{'disk_total'}, $info->{'disk_free'}); + my ($total, $free, $used) = + ($info->{'disk_total'}, + $info->{'disk_free'}, + $info->{'disk_fs'} ? + $info->{'disk_fs'}->[0]->{'used'} : undef); push(@table, { 'desc' => $text{'right_disk'}, 'value' => &text('right_used', &nice_size($total), - &nice_size($total-$free)), - 'chart' => [ $total, $total-$free ] }); + &nice_size($used // $total-$free)), + 'chart' => [ $total, $used // $total-$free ] }); } # Warnings about filesystems running low on space