Fixed and improved the calculation of 'Used' in .memory.pm'

There was a stupid bug that prevented to include the SReclaimable value in the
formula to calculate the 'Used' value.

Morever, I've seen that newer versions of 'free' command also include the value
SUnreclaim in that formula. So, the final calculation of 'Used' is like this:

Used = MemTotal - MemFree - Buffers - Cached - SReclaimable - SUnreclaim

This ensures that Monitorix is in sync with the results of 'free' command. #204
This commit is contained in:
Jordi Sanfeliu 2019-03-08 11:19:05 +01:00
parent 9d26e28f90
commit b290ffd417
1 changed files with 10 additions and 1 deletions

View File

@ -168,6 +168,7 @@ sub system_update {
my $uptime = 0; my $uptime = 0;
my $srecl = 0; my $srecl = 0;
my $snorecl = 0;
my $rrdata = "N"; my $rrdata = "N";
if($config->{os} eq "Linux") { if($config->{os} eq "Linux") {
@ -236,11 +237,19 @@ sub system_update {
} }
if(/^SReclaimable:\s+(\d+) kB$/) { if(/^SReclaimable:\s+(\d+) kB$/) {
$srecl = $1; $srecl = $1;
next;
}
if(/^SUnreclaim:\s+(\d+) kB$/) {
$snorecl = $1;
last; last;
} }
} }
close(IN); close(IN);
$mfree -= $srecl; # SReclaimable is subtracted here
# SReclaimable and SUnreclaim values are added to 'mfree'
# in order to be also included in the subtraction later.
$mfree += $srecl;
$mfree += $snorecl;
open(IN, "/proc/sys/kernel/random/entropy_avail"); open(IN, "/proc/sys/kernel/random/entropy_avail");
while(<IN>) { while(<IN>) {