1#!@@PERL@@ -w
2# -*- perl -*-
3
4=head1 NAME
5
6snmp__memory - Munin plugin to monitor memory usage of a remote host
7via SNMP.
8
9=head1 CONFIGURATION
10
11The following configuration variables are used
12
13 host      - SNMP host to contact (default taken from link name)
14 port      - SNMP port to use (default 161)
15 community - SNMP community string to use (default "public")
16
17=head1 NOTES
18
19Based on snmp__df plugin.... If this plugin reports
20different numbers from the snmp_winmem plugin it must be due
21to snmp impementation quirks....
22
23=head1 AUTHOR
24
25Copyright (C) 2006 Lars Strand
26
27=head1 LICENSE
28
29This program is free software; you can redistribute it and/or
30modify it under the terms of the GNU General Public License
31as published by the Free Software Foundation; version 2 dated June,
321991.
33
34This program is distributed in the hope that it will be useful,
35but WITHOUT ANY WARRANTY; without even the implied warranty of
36MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37GNU General Public License for more details.
38
39You should have received a copy of the GNU General Public License
40along with this program; if not, write to the Free Software
41Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
42
43=head1 MAGIC MARKERS
44
45 #%# family=snmpauto
46 #%# capabilities=snmpconf
47
48=cut
49
50use strict;
51use Munin::Plugin::SNMP;
52
53
54# memory usage pr. process
55my $hrSWRunPerfMem = "1.3.6.1.2.1.25.5.1.1.2.";
56my $hrMemorySize = "1.3.6.1.2.1.25.2.2.0";
57
58if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
59{
60    print "require $hrSWRunPerfMem\n";
61    print "require $hrSWRunPerfMem [1-9]\n";
62    print "require $hrMemorySize\n"; # memsize
63    exit 0;
64}
65
66my $session = Munin::Plugin::SNMP->session();
67my $memsize = $session->get_single($hrMemorySize) * 1024;
68
69if (defined $ARGV[0] and $ARGV[0] eq "config")
70{
71    my ($host) = Munin::Plugin::SNMP->config_session();
72    print "host_name $host\n";
73    print "graph_title Memory usage\n";
74    print "graph_category system\n";
75    print "graph_vlabel Bytes\n";
76    print "graph_info This grap shows memory usage.\n";
77
78    # some devices reports negative memtotal value
79    print "# Total memsize reported $memsize..." if $Munin::Plugin::SNMP::DEBUG;
80
81    if ($memsize > 0)
82    {
83        print "graph_args --base 1024 -l 0 --upper-limit $memsize\n";
84    }
85    else
86    {
87        print "graph_args --base 1024 -l 0\n";
88    }
89
90    print "memory.draw AREA\n";
91    print "memory.label memory\n";
92
93    exit 0;
94}
95
96# calculate total memory
97my $processes = $session->get_by_regex ($hrSWRunPerfMem, "[1-9]");
98
99# the values
100my $memtotal = 0;
101while (my ($pid, $mem) = each(%$processes)) {
102    $memtotal += $mem;
103}
104
105printf "memory.value %d\n", $memtotal * 1024;
106