summaryrefslogtreecommitdiff
path: root/mrtg-memuse
blob: c8068f06ebd97e5479cdf7879c5d6ccae804f6c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl -w
# (c) 2003 by Gerfried Fuchs <alfie@sil.at>, MIT license
#
# mrtg memory and swap usage check

use strict;

open(FOO, "/usr/bin/free -b|") || die "$0: can't fork free: $!";
my (undef, $mem, $mem2, $swap) = <FOO>;
close FOO;

chomp($mem, $mem2, $swap);

my ($memtot) = $mem =~ /^\S+\s+(\d+)\s+/;
my ($memuse) = $mem2 =~ /^\S+ \S+\s+(\d+)\s+/;

my ($swaptot, $swapuse) = $swap =~ /^\S+\s+(\d+)\s+(\d+)\s+/;

print "$memuse\n$swapuse\n".`/usr/bin/uptime`.`/bin/hostname`;

__END__
             total       used       free     shared    buffers     cached
Mem:        514336     489352      24984          0      87716     171732
-/+ buffers/cache:     229904     284432
Swap:       514040      64012     450028