#!/usr/bin/perl
#
# aoserv-mrtg - MRTG configured by the AOServ Platform.
# Copyright (C) 2016, 2018, 2026  AO Industries, Inc.
#     support@aoindustries.com
#     7262 Bull Pen Cir
#     Mobile, AL 36695
#
# This file is part of aoserv-mrtg.
#
# aoserv-mrtg is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# aoserv-mrtg is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with aoserv-mrtg.  If not, see <http://www.gnu.org/licenses/>.
#

my $memtotal = 0;
my $memfree = 0;
my $swaptotal = 0;
my $swapfree = 0;
open PROC, "/proc/meminfo";
while(<PROC>) {
  chomp;
  ($name, $value) = ($_ =~ /(\S+):\s+(\S+)/sm);
  if($name eq 'MemTotal') {
    $memtotal = $value;
  } elsif($name eq 'MemFree') {
    $memfree = $value;
  } elsif($name eq 'SwapTotal') {
    $swaptotal = $value;
  } elsif($name eq 'SwapFree') {
    $swapfree = $value;
  }
}
close PROC;
if($memtotal == 0) {
  $mempercent = 0;
} else {
  $mempercent = 100 * (($memtotal - $memfree) / $memtotal);
}
if($swaptotal == 0) {
  $swappercent = 0;
} else {
  $swappercent = 100 * (($swaptotal - $swapfree) / $swaptotal);
}

printf "%.0f\n%.0f\n1\nSystem Memory and Swap\n", $swappercent, $mempercent;
