]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
index.cgi: Simplify code for checking disk usage.
authorStefan Schantl <stefan.schantl@ipfire.org>
Fri, 15 Mar 2024 12:53:36 +0000 (13:53 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Fri, 15 Mar 2024 12:53:36 +0000 (13:53 +0100)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
html/cgi-bin/index.cgi

index 65773244c5d67bed9ac7dc6abde32a58f09a94c0..14ebab603d1255a5a0e5628952db35457718613e 100644 (file)
@@ -559,28 +559,21 @@ if ($used / $mem > 90) {
 }
 
 # Diskspace usage warning
-my @temp=();
-my $temp2=();
-my @df = `/bin/df -B M -P -x rootfs`;
+my @df = `/bin/df -B M -P -x tmpfs -x devtmpfs`;
 foreach my $line (@df) {
+       # Skip headline.
        next if $line =~ m/^Filesystem/;
-       if ($line =~ m/root/ ) {
-               $line =~ m/^.* (\d+)M.*$/;
-               @temp = split(/ +/,$line);
-               if ($1<5) {
-                       # available:plain value in MB, and not %used as 10% is too much to waste on small disk
-                       # and root size should not vary during time
-                       $warnmessage .= "<li>$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>";
-               }
+        
+       # Splitt processed line and assign some nice humand-readable values.
+       my($dev, $blocks_1k, $used, $available, $used_percent, $mpoint) = split(/\s+/, $line);
 
-       } else {
-               # $line =~ m/^.* (\d+)m.*$/;
-               $line =~ m/^.* (\d+)\%.*$/;
-               if ($1>90) {
-                       @temp = split(/ /,$line);
-                       $temp2=int(100-$1);
-                       $warnmessage .= "<li>$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>";
-               }
+       # Check if more than 90% of disk is consumed.
+       if ($used_percent > 90) {
+               # Calculate remain free space.
+               my $free=int(100-$used_percent);
+
+               # Add a warning message.
+               $warnmessage .= "<li>$Lang::tr{'filesystem full'}: $dev <b>$Lang::tr{'free'}=$free%</b> !</li>";
        }
 }