]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
memory.cgi: Fix memory usage table
authorLeo-Andres Hofmann <hofmann@leo-andres.de>
Tue, 8 Jun 2021 06:37:18 +0000 (08:37 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 10 Jun 2021 09:12:15 +0000 (09:12 +0000)
procps 3.3.10 introduced a new output format for the "free" command.
This patch adapts the new format.

Fixes: #12628
Signed-off-by: Leo-Andres Hofmann <hofmann@leo-andres.de>
Tested-by: Bernhard Bitsch <bbitsch@ipfire.org>
Tested-by: Bernhard Bitsch <bbitsch@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
html/cgi-bin/memory.cgi
langs/de/cgi-bin/de.pl
langs/en/cgi-bin/en.pl

index 204365294e1cfa9446402e1f52c8805b4e514d7a..89fa7d14a380b98ecc441bf83bab201b96de168e 100644 (file)
@@ -64,7 +64,6 @@ if ( $querry[0] =~ "memory"){
        
        &Header::openbox('100%', 'center', $Lang::tr{'memory'});
        print "<table width='95%' cellspacing='5'>";
-       my $ram=0;
        my $size=0;
        my $used=0;
        my $free=0;
@@ -72,10 +71,12 @@ if ( $querry[0] =~ "memory"){
        my $shared=0;
        my $buffers=0;
        my $cached=0;
+       my $available=0;
 
-       open(FREE,'/usr/bin/free |');
-       while(<FREE>){
-               if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ ){
+       # output format: kibibytes, wide mode (buffers and cache in two columns)
+       open(my $cmd_fh, "-|", '/usr/bin/free -k -w') or die $!;
+       while(<$cmd_fh>){
+               if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cache\s+available$/ ){
                        print <<END
 <tr>
 <td align='center'>&nbsp;</td>
@@ -87,13 +88,12 @@ if ( $querry[0] =~ "memory"){
 END
 ;
                }else{
-                       if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/){
-                               ($ram,$size,$used,$free,$shared,$buffers,$cached) = ($1,$1,$2,$3,$4,$5,$6);
+                       if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/){
+                               ($size,$used,$free,$shared,$buffers,$cached,$available) = ($1,$2,$3,$4,$5,$6,$7);
                                ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
                                print <<END
 <tr>
 <td class='boldbase'><b>$Lang::tr{'ram'}</b></td>
-<td align='center'>$size  KB</td>
 END
 ;
                        }elsif($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/){
@@ -106,17 +106,13 @@ END
                                print <<END
 <tr>
 <td class='boldbase'><b>$Lang::tr{'swap'}</b></td>
-<td align='center'>$size  KB</td>
 END
 ;
-                       }elsif($ram and $_ =~ m/^-\/\+ buffers\/cache:\s+(\d+)\s+(\d+)$/ ){
-                               ($used,$free) = ($1,$2);
-                               ($percent = ($used/$ram)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
-                               print "<tr><td colspan='2' class='boldbase'><b>$Lang::tr{'excluding buffers and cache'}</b></td>";
                        }
                        print <<END
-<td align='center'>$used KB</td>
-<td align='center'>$free KB</td>
+<td align='center'>$size KiB</td>
+<td align='center'>$used KiB</td>
+<td align='center'>$free KiB</td>
 <td>
 END
 ;
@@ -129,12 +125,13 @@ END
 ;
                }
        }
-       close FREE;
+       close($cmd_fh);
        print <<END
-<tr><td class='boldbase' colspan='2'><br /></td></tr>
-<tr><td class='boldbase'><b>$Lang::tr{'shared'}</b></td><td align='center'>$shared KB</td></tr>
-<tr><td class='boldbase'><b>$Lang::tr{'buffers'}</b></td><td align='center'>$buffers KB</td></tr>
-<tr><td class='boldbase'><b>$Lang::tr{'cached'}</b></td><td align='center'>$cached KB</td></tr>
+<tr><td colspan='6'><br /></td></tr>
+<tr><td class='boldbase'><b>$Lang::tr{'shared'}</b></td><td align='center'>$shared KiB</td></tr>
+<tr><td class='boldbase'><b>$Lang::tr{'buffers'}</b></td><td align='center'>$buffers KiB</td></tr>
+<tr><td class='boldbase'><b>$Lang::tr{'cached'}</b></td><td align='center'>$cached KiB</td></tr>
+<tr><td class='boldbase'><b>$Lang::tr{'available'}</b></td><td align='center'>$available KiB</td></tr>
 </table>
 END
 ;
index 0bc579cd26260fbea6cfd95545f10f1711f96edd..058ec7b07ba59c57f5dae07dee80748cfaaa65e5 100644 (file)
 'cache management' => 'Cache-Verwaltung',
 'cache size' => 'Cache-Größe (MB):',
 'cached' => 'zwischengespeichert',
+'available' => 'verfügbar',
 'cached memory' => 'Zwischenspeicher ',
 'cached swap' => 'Zwischenspeicher (Swap)',
 'calamaris available reports' => 'Verfügbare Berichte',
index 1c69b37988c01a9d0441fb203204f6c92748a52e..942c67f2065c891ec37bdd937a603b068e469079 100644 (file)
 'cache management' => 'Cache management',
 'cache size' => 'Cache size (MB):',
 'cached' => 'cached',
+'available' => 'available',
 'cached memory' => 'Cached Memory  ',
 'cached swap' => 'Cached Swap',
 'calamaris available reports' => 'Available reports',