]>
Commit | Line | Data |
---|---|---|
3decc5d1 JR |
1 | #!/usr/bin/perl -w |
2 | # -*- perl -*- | |
3 | # vim: ft=perl | |
4 | # | |
5 | # Copyright (C) 2006 Lars Strand | |
6 | # | |
7 | # Munin plugin to monitor swap usage by use of SNMP. | |
8 | # Based on the snmp__df plugin | |
9 | # | |
10 | # This program is free software; you can redistribute it and/or | |
11 | # modify it under the terms of the GNU General Public License | |
12 | # as published by the Free Software Foundation; version 2 dated June, | |
13 | # 1991. | |
14 | # | |
15 | # This program is distributed in the hope that it will be useful, | |
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | # GNU General Public License for more details. | |
19 | # | |
20 | # You should have received a copy of the GNU General Public License | |
21 | # along with this program; if not, write to the Free Software | |
22 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
23 | # | |
24 | # $Log$ | |
25 | # | |
26 | #%# family=snmpauto | |
27 | #%# capabilities=snmpconf | |
28 | ||
29 | use strict; | |
30 | use Munin::Plugin::SNMP; | |
31 | ||
32 | ||
33 | my $response; | |
34 | ||
35 | if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") { | |
36 | # HOST-RESOURCES-MIB::hrStorageType | |
37 | # HOST-RESOURCES-TYPES::hrStorageVirtualMemory | |
38 | print "require 1.3.6.1.2.1.25.2.3.1.2. 1.3.6.1.2.1.25.2.1.3\n"; | |
39 | exit 0; | |
40 | } | |
41 | ||
42 | my $session = Munin::Plugin::SNMP->session(); | |
43 | ||
44 | my $hrStorage = "1.3.6.1.2.1.25.2."; | |
45 | my $hrStorageVirtualMemory = "1.3.6.1.2.1.25.2.1.3"; | |
46 | my $hrStorageSize = "1.3.6.1.2.1.25.2.3.1.5."; | |
47 | my $hrStorageUsed = "1.3.6.1.2.1.25.2.3.1.6."; | |
48 | ||
49 | my $swap_d = $session->get_by_regex($hrStorage, $hrStorageVirtualMemory); | |
50 | ||
51 | my $swapsize = 0; | |
52 | my $swapused = 0; | |
53 | ||
54 | foreach my $swap (keys %$swap_d) { | |
55 | $swapsize += $session->get_single($hrStorageSize . $swap); | |
56 | $swapused += $session->get_single($hrStorageUsed . $swap); | |
57 | } | |
58 | ||
59 | if (defined $ARGV[0] and $ARGV[0] eq "config") { | |
60 | my ($host) = Munin::Plugin::SNMP->config_session(); | |
61 | print "host_name $host\n" unless $host eq 'localhost'; | |
62 | print "graph_title Virtual memory usage\n"; | |
63 | if ($swapsize > 0) { | |
64 | print "graph_args -l 0 --base 1024 --upper-limit $swapsize\n"; | |
65 | } else { | |
66 | print "graph_args -l 0 --base 1024\n"; | |
67 | } | |
68 | print "graph_vlabel Bytes\n"; | |
69 | print "graph_category system\n"; | |
70 | print "graph_info This graph shows swap usage in bytes.\n"; | |
71 | print "swap.label swap\n"; | |
72 | print "swap.type DERIVE\n"; | |
73 | print "swap.min 0\n"; | |
74 | exit 0; | |
75 | } | |
76 | ||
77 | print "swap.value $swapused\n"; | |
78 |