From patchwork Tue Jun 8 06:37:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Leo-Andres Hofmann X-Patchwork-Id: 4406 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4FzgXT1wsDz3x6s for ; Tue, 8 Jun 2021 06:37:45 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4FzgXQ62ytz18C; Tue, 8 Jun 2021 06:37:42 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4FzgXQ2cDSz2xNt; Tue, 8 Jun 2021 06:37:42 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4FzgXN1XKLz2y2L for ; Tue, 8 Jun 2021 06:37:40 +0000 (UTC) Received: from arche.uberspace.de (arche.uberspace.de [185.26.156.147]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4FzgXG58vZzrY for ; Tue, 8 Jun 2021 06:37:34 +0000 (UTC) Received: (qmail 9565 invoked from network); 8 Jun 2021 06:37:29 -0000 Received: from localhost (HELO localhost) (127.0.0.1) by arche.uberspace.de with SMTP; 8 Jun 2021 06:37:29 -0000 From: Leo-Andres Hofmann To: development@lists.ipfire.org Subject: [PATCH 1/2] memory.cgi: Fix memory usage table Date: Tue, 8 Jun 2021 08:37:18 +0200 Message-Id: <20210608063719.283-1-hofmann@leo-andres.de> X-Mailer: git-send-email 2.27.0.windows.1 MIME-Version: 1.0 ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=none; spf=pass (mail01.ipfire.org: domain of hofmann@leo-andres.de designates 185.26.156.147 as permitted sender) smtp.mailfrom=hofmann@leo-andres.de ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1623134255; a=rsa-sha256; cv=none; b=NoJyRoDl9hicCVgRtXr9nHpTzotLMKLCZ8fEEeJMaJxb1FqLlSvid3WkERmHG6aJyHX5KN Jr9yYIWXH0JBRK9TL8bwnUXz4C43wuNwvYMqv4e1Rgr4M0HPxurPChLMHudBFRAC401QJ6 C9wY8oQaZGTMrnO4b7YGQKvlGAHFUXUQLpkpkjxIsCQzhrNJaP6I2xeI5Kjzg4WPW/TnbX sJVjp893bIVEINmFGpGiCeH4e+KAFzJWAZwMigTwInIDlD3SmGN+buUFjTz+B9AgHZy6g/ 4VexnAtNY6rSQh1vG8jYu0vYfdb4/a1QclMV29Nq3BjBn2niSbRtC4FJWIboCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1623134254; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Ryjw1C95dvwI0Haf9drJ/oLIpfsQcgXbCBlrgGt0oKc=; b=qCCtx2uxn1B1BIzRHPQd9Xv9EaH7zyipPNbsJunK5TKb9X6kCS8xmfD0MHPBZ1Oa1LZyDa j0TMgf9yLalM3XZGV7VsIIGLaShYMUhVVANWc0Fq8LAotCMtMLCcfBCH7y0f1T4LLjtMMw x92GMOxdviQgLxtd8Bj+MEi4vq/NlWes2lAhuI43PQLiZ6c633ci4Ze3r/MeScLaFNTJ4U 7Ce1rRQEO4FsnX6/d+GauDU91ImPigZMbhAib9PgH702yzHOpWGy5tZ9H3zCnWsbxMNh4k SQykDX0RQ3cuy9hC8c1JHlCHNOg8cKdkTlF5sApGuaeiFwhMCaNQecCaR3mBWA== X-Rspamd-Server: mail01.haj.ipfire.org X-Spamd-Result: default: False [-2.60 / 11.00]; RCVD_TLS_LAST(0.00)[]; ARC_NA(0.00)[]; MX_INVALID(0.50)[]; FROM_HAS_DN(0.00)[]; SPF_REPUTATION_HAM(-0.80)[-0.79655910277327]; TO_MATCH_ENVRCPT_ALL(0.00)[]; IP_REPUTATION_HAM(-0.01)[asn: 205766(0.00), country: DE(-0.01), ip: 185.26.156.147(0.00)]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; RCPT_COUNT_ONE(0.00)[1]; DMARC_NA(0.00)[leo-andres.de]; R_SPF_ALLOW(-0.20)[+mx]; MID_CONTAINS_FROM(1.00)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:205766, ipnet:185.26.156.0/24, country:DE]; RCVD_COUNT_TWO(0.00)[2]; BAYES_HAM(-3.00)[99.99%] X-Rspamd-Queue-Id: 4FzgXG58vZzrY Authentication-Results: mail01.ipfire.org; dkim=none; spf=pass (mail01.ipfire.org: domain of hofmann@leo-andres.de designates 185.26.156.147 as permitted sender) smtp.mailfrom=hofmann@leo-andres.de; dmarc=none X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" 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 Tested-by: Bernhard Bitsch Tested-by: Bernhard Bitsch --- 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(-) 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] =~ "memory"){ &Header::openbox('100%', 'center', $Lang::tr{'memory'}); print ""; - 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(){ - 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 < @@ -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 ; }elsif($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/){ @@ -106,17 +106,13 @@ END print < - END ; - }elsif($ram and $_ =~ m/^-\/\+ buffers\/cache:\s+(\d+)\s+(\d+)$/ ){ - ($used,$free) = ($1,$2); - ($percent = ($used/$ram)*100) =~ s/^(\d+)(\.\d+)?$/$1%/; - print ""; } print <$used KB - + + + - - - + + + + +
 $Lang::tr{'ram'}$size KB$Lang::tr{'swap'}$size KB
$Lang::tr{'excluding buffers and cache'}$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' => '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', 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' => 'Cache management', 'cache size' => 'Cache size (MB):', 'cached' => 'cached', +'available' => 'available', 'cached memory' => 'Cached Memory ', 'cached swap' => 'Cached Swap', 'calamaris available reports' => 'Available reports',