From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bernhard Bitsch To: development@lists.ipfire.org Subject: Re: [PATCH 1/2] memory.cgi: Fix memory usage table Date: Tue, 08 Jun 2021 13:50:05 +0200 Message-ID: <43c271dd-5183-49ab-1884-3a3570745a7a@ipfire.org> In-Reply-To: <20210608063719.283-1-hofmann@leo-andres.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5066120439064729007==" List-Id: --===============5066120439064729007== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Applied and tested. Am 08.06.2021 um 08:37 schrieb Leo-Andres Hofmann: > procps 3.3.10 introduced a new output format for the "free" command. > This patch adapts the new format. >=20 > Fixes: #12628 >=20 > Signed-off-by: Leo-Andres Hofmann > --- > html/cgi-bin/memory.cgi | 35 ++++++++++++++++------------------- > langs/de/cgi-bin/de.pl | 1 + > langs/en/cgi-bin/en.pl | 1 + > 3 files changed, 18 insertions(+), 19 deletions(-) >=20 > diff --git a/html/cgi-bin/memory.cgi b/html/cgi-bin/memory.cgi > index 204365294..89fa7d14a 100644 > --- a/html/cgi-bin/memory.cgi > +++ b/html/cgi-bin/memory.cgi > @@ -64,7 +64,6 @@ if ( $querry[0] =3D~ "memory"){ > =09 > &Header::openbox('100%', 'center', $Lang::tr{'memory'}); > print ""; > - my $ram=3D0; > my $size=3D0; > my $used=3D0; > my $free=3D0; > @@ -72,10 +71,12 @@ if ( $querry[0] =3D~ "memory"){ > my $shared=3D0; > my $buffers=3D0; > my $cached=3D0; > + my $available=3D0; > =20 > - open(FREE,'/usr/bin/free |'); > - while(){ > - if ($_ =3D~ 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 ($_ =3D~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cache\s+avail= able$/ ){ > print < > > @@ -87,13 +88,12 @@ if ( $querry[0] =3D~ "memory"){ > END > ; > }else{ > - if ($_ =3D~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/){ > - ($ram,$size,$used,$free,$shared,$buffers,$cached) =3D ($1,$1,$2,$3,$4,= $5,$6); > + if ($_ =3D~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(= \d+)$/){ > + ($size,$used,$free,$shared,$buffers,$cached,$available) =3D ($1,$2,$3,= $4,$5,$6,$7); > ($percent =3D ($used/$size)*100) =3D~ s/^(\d+)(\.\d+)?$/$1%/; > print < > > - > END > ; > }elsif($_ =3D~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/){ > @@ -106,17 +106,13 @@ END > print < > > - > END > ; > - }elsif($ram and $_ =3D~ m/^-\/\+ buffers\/cache:\s+(\d+)\s+(\d+)$/ ){ > - ($used,$free) =3D ($1,$2); > - ($percent =3D ($used/$ram)*100) =3D~ s/^(\d+)(\.\d+)?$/$1%/; > - print ""; > } > print < - > - > + > + > + > > - > - > - > + > + > + > + > + >
 
$Lang::tr{'ram'}$size KB
$Lang::tr{'swap'}$size KB
$Lang::tr{'excludin= g buffers and cache'}$used KB$free KB$size KiB$used KiB$free KiB > END > ; > @@ -129,12 +125,13 @@ END > ; > } > } > - close FREE; > + close($cmd_fh); > print < -

$Lang::tr{'shared'}$shared KB
$Lang::tr{'buffers'}$buffers KB
$Lang::tr{'cached'}$cached KB

$Lang::tr{'shared'}$shared KiB
$Lang::tr{'buffers'}$buffers KiB
$Lang::tr{'cached'}$cached KiB
$Lang::tr{'available'}$available KiB
> END > ; > diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl > index 0bc579cd2..058ec7b07 100644 > --- a/langs/de/cgi-bin/de.pl > +++ b/langs/de/cgi-bin/de.pl > @@ -507,6 +507,7 @@ > 'cache management' =3D> 'Cache-Verwaltung', > 'cache size' =3D> 'Cache-Gr=C3=B6=C3=9Fe (MB):', > 'cached' =3D> 'zwischengespeichert', > +'available' =3D> 'verf=C3=BCgbar', > 'cached memory' =3D> 'Zwischenspeicher ', > 'cached swap' =3D> 'Zwischenspeicher (Swap)', > 'calamaris available reports' =3D> 'Verf=C3=BCgbare Berichte', > diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl > index 1c69b3798..942c67f20 100644 > --- a/langs/en/cgi-bin/en.pl > +++ b/langs/en/cgi-bin/en.pl > @@ -522,6 +522,7 @@ > 'cache management' =3D> 'Cache management', > 'cache size' =3D> 'Cache size (MB):', > 'cached' =3D> 'cached', > +'available' =3D> 'available', > 'cached memory' =3D> 'Cached Memory ', > 'cached swap' =3D> 'Cached Swap', > 'calamaris available reports' =3D> 'Available reports', >=20 --===============5066120439064729007==--