mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
Fix OpenWrt SNMP memory plugin
This commit is contained in:
parent
f2de5497bd
commit
cbe99fd9fa
1 changed files with 75 additions and 89 deletions
|
@ -1,76 +1,81 @@
|
||||||
#!/usr/bin/perl -w
|
#!/usr/local/bin/perl -w
|
||||||
#
|
# -*- perl -*-
|
||||||
# Copyright (C) 2008 J.M.Roth
|
# vim: ft=perl
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or
|
=head1 NAME
|
||||||
# modify it under the terms of the GNU General Public License
|
|
||||||
# as published by the Free Software Foundation; version 2 dated June,
|
snmp__memory_openwrt - Munin plugin to monitor the memory usage of an OpenWrt
|
||||||
# 1991.
|
device.
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
=head1 APPLICABLE SYSTEMS
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
OpenWrt devices which have snmpd installed.
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
=head1 CONFIGURATION
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program; if not, write to the Free Software
|
As a rule SNMP plugins need site specific configuration. The default
|
||||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
configuration (shown here) will only work on insecure sites/devices.
|
||||||
#
|
|
||||||
#
|
[snmp_*]
|
||||||
# $Log$
|
env.version 2
|
||||||
#
|
env.community public
|
||||||
# Inspired by snmp__processes
|
|
||||||
#
|
In general SNMP is not very secure at all unless you use SNMP version
|
||||||
#%# family=snmpauto
|
3 which supports authentication and privacy (encryption). But in any
|
||||||
#%# capabilities=snmpconf
|
case the community string for your devices should not be "public".
|
||||||
|
|
||||||
|
Please see 'perldoc Munin::Plugin::SNMP' for further configuration
|
||||||
|
information.
|
||||||
|
|
||||||
|
=head1 INTERPRETATION
|
||||||
|
|
||||||
|
The total and used memory on the system.
|
||||||
|
|
||||||
|
=head1 MIB INFORMATION
|
||||||
|
|
||||||
|
This plugin requires support for the HOST-RESOURCES-MIB (RFC 2790). It
|
||||||
|
reports the contents of the hrStorageSize and hrStorageUsed OIDs.
|
||||||
|
|
||||||
|
=head1 MAGIC MARKERS
|
||||||
|
|
||||||
|
#%# family=snmpauto
|
||||||
|
#%# capabilities=snmpconf
|
||||||
|
|
||||||
|
=head1 VERSION
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
|
||||||
|
=head1 BUGS
|
||||||
|
|
||||||
|
None known.
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Copyright (C) 2017 Hanson Wong
|
||||||
|
|
||||||
|
Based on snmp__memory_openwrt (C) 2008 J.M.Roth
|
||||||
|
|
||||||
|
=head1 LICENSE
|
||||||
|
|
||||||
|
GPLv2.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Net::SNMP;
|
use Munin::Plugin::SNMP;
|
||||||
|
|
||||||
my $DEBUG = 0;
|
if (defined $ARGV[0] and $ARGV[0] eq 'snmpconf') {
|
||||||
|
print "require 1.3.6.1.2.1.25.2.3.1.5.1\n";
|
||||||
my $host = $ENV{host} || undef;
|
print "require 1.3.6.1.2.1.25.2.3.1.6.1\n";
|
||||||
my $port = $ENV{port} || 161;
|
|
||||||
my $community = $ENV{community} || "public";
|
|
||||||
my $iface = $ENV{interface} || undef;
|
|
||||||
|
|
||||||
my $response;
|
|
||||||
|
|
||||||
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
|
|
||||||
{
|
|
||||||
print "require 1.3.6.1.2.1.25.2.3.1.5.2\n"; # Number
|
|
||||||
print "require 1.3.6.1.2.1.25.2.3.1.6.2\n"; # Number
|
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
my @split_result = split(/_/, $0);
|
if (defined $ARGV[0] and $ARGV[0] eq "config") {
|
||||||
$host = $split_result[1];
|
my ($host) = Munin::Plugin::SNMP->config_session();
|
||||||
if ($host =~ /^([^:]+):(\d+)$/)
|
|
||||||
{
|
|
||||||
$host = $1;
|
|
||||||
$port = $2;
|
|
||||||
}
|
|
||||||
if ($host eq '' || !defined $host)
|
|
||||||
{
|
|
||||||
print "# Debug: $0 -- $1\n" if $DEBUG;
|
|
||||||
die "# Error: couldn't understand what I'm supposed to monitor.";
|
|
||||||
}
|
|
||||||
|
|
||||||
my ($session, $error) = Net::SNMP->session(
|
print "host_name $host\n" unless ($host eq 'localhost');
|
||||||
-hostname => $host,
|
print <<'EOC';
|
||||||
-community => $community,
|
graph_title Memory usage
|
||||||
-port => $port
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!defined ($session))
|
|
||||||
{
|
|
||||||
die "Croaking: $error";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defined $ARGV[0] and $ARGV[0] eq "config")
|
|
||||||
{
|
|
||||||
print "host_name $host\n";
|
|
||||||
print "graph_title Memory usage
|
|
||||||
graph_args --base 1000 -l 0
|
graph_args --base 1000 -l 0
|
||||||
graph_vlabel kB
|
graph_vlabel kB
|
||||||
graph_category memory
|
graph_category memory
|
||||||
|
@ -81,29 +86,10 @@ memsize.info The total memory.
|
||||||
memused.info The memory in use.
|
memused.info The memory in use.
|
||||||
memsize.draw LINE1
|
memsize.draw LINE1
|
||||||
memused.draw LINE2
|
memused.draw LINE2
|
||||||
";
|
EOC
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
print "memsize.value ", &get_single ($session, "1.3.6.1.2.1.25.2.3.1.5.2"), "\n";
|
my $session = Munin::Plugin::SNMP->session();
|
||||||
print "memused.value ", &get_single ($session, "1.3.6.1.2.1.25.2.3.1.6.2"), "\n";
|
print "memsize.value ", $session->get_single('1.3.6.1.2.1.25.2.3.1.5.1'), "\n";
|
||||||
|
print "memused.value ", $session->get_single('1.3.6.1.2.1.25.2.3.1.6.1'), "\n";
|
||||||
sub get_single
|
|
||||||
{
|
|
||||||
my $handle = shift;
|
|
||||||
my $oid = shift;
|
|
||||||
|
|
||||||
print "# Getting single $oid...\n" if $DEBUG;
|
|
||||||
|
|
||||||
$response = $handle->get_request ($oid);
|
|
||||||
|
|
||||||
if (!defined $response->{$oid})
|
|
||||||
{
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return $response->{$oid};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue