#!/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/>.
#

# disk space
my $spacetotal = 0;
my $spaceusage = 0;
open DF, "/bin/df -Plk |";
while(<DF>) {
  if(/^\Q$ARGV[0]\E\s/) {
    my @df = split;
    $spacetotal = $df[1];
    $spaceusage = $df[2];
    last;
  }
}
close DF;
if($spacetotal == 0) {
  $spacepercent = 0;
} else {
  $spacepercent = 100 * $spaceusage / $spacetotal;
}

# inodes
my $inodetotal = 0;
my $inodeusage = 0;
open DF, "/bin/df -Plki |";
while(<DF>) {
  if(/^\Q$ARGV[0]\E\s/) {
    my @df = split;
    $inodetotal = $df[1];
    $inodeusage = $df[2];
    last;
  }
}
close DF;
if($inodetotal == 0) {
  $inodepercent = 0;
} else {
  $inodepercent = 100 * $inodeusage / $inodetotal;
}

printf "%.1f\n%.1f\n100\nDisk Space and Inodes for $ARGV[0]\n", $spacepercent, $inodepercent;
