1#!@@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 29use strict; 30use Munin::Plugin::SNMP; 31 32 33my $response; 34 35if (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 42my $session = Munin::Plugin::SNMP->session(); 43 44my $hrStorage = "1.3.6.1.2.1.25.2."; 45my $hrStorageVirtualMemory = "1.3.6.1.2.1.25.2.1.3"; 46my $hrStorageSize = "1.3.6.1.2.1.25.2.3.1.5."; 47my $hrStorageUsed = "1.3.6.1.2.1.25.2.3.1.6."; 48 49my $swap_d = $session->get_by_regex($hrStorage, $hrStorageVirtualMemory); 50 51my $swapsize = 0; 52my $swapused = 0; 53 54foreach my $swap (keys %$swap_d) { 55 $swapsize += $session->get_single($hrStorageSize . $swap); 56 $swapused += $session->get_single($hrStorageUsed . $swap); 57} 58 59if (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 disk\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 77print "swap.value $swapused\n"; 78 79