6
snmp__cpuload - Munin plugin to monitor CPU-load by use of SNMP.
10
The following environment variables are used by this plugin:
12
host - SNMP host (default taken from plugin link name)
13
port - SNMP port (default 161)
14
community - SNMP community (default "private")
18
Based on snmp__df plugin.
22
Copyright (C) 2006 Lars Strand
26
This program is free software; you can redistribute it and/or modify
27
it under the terms of the GNU General Public License as published by
28
the Free Software Foundation; version 2 dated June, 1991.
30
This program is distributed in the hope that it will be useful, but
31
WITHOUT ANY WARRANTY; without even the implied warranty of
32
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33
General Public License for more details.
35
You should have received a copy of the GNU General Public License
36
along with this program; if not, write to the Free Software
37
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
43
#%# capabilities=snmpconf
52
my $host = $ENV{host} || undef;
53
my $port = $ENV{port} || 161;
54
my $community = $ENV{community} || "public";
58
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
60
print "index 1.3.6.1.2.1.25.3.3.1.2.\n";
61
print "require 1.3.6.1.2.1.25.3.3.1.2.1\n"; # CPU #1
65
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_cpuload$/)
68
if ($host =~ /^([^:]+):(\d+)$/)
75
elsif (!defined($host))
77
print "# Debug: $0 -- $1\n" if $DEBUG;
78
die "# Error: couldn't understand what I'm supposed to monitor.";
82
my $hrProcessorLoad = "1.3.6.1.2.1.25.3.3.1.2.";
84
my ($session, $error) = Net::SNMP->session(
86
-community => $community,
90
if (!defined ($session))
92
die "Croaking: $error";
95
# Bug? Only up to 9 cpus?
96
my $cpus = get_by_regex($session, $hrProcessorLoad, "[1-9]");
99
if (defined $ARGV[0] and $ARGV[0] eq "config")
101
print "host_name $host\n";
102
print "graph_title CPU usage (in %)
103
graph_category system
104
graph_args --upper-limit 100 -l 0
106
graph_info This graph shows the CPU load on the system.
108
foreach my $cpu (keys %$cpus)
110
# CPU #1 will have $fieldname "cpu" to retain compatability with
111
# old snmp_cpuload plugin.
113
$cpun='' if $cpun ==1;
114
print "cpu$cpun.label CPU $cpu\n";
115
print "cpu$cpun.info CPU load on CPU $cpu\n";
121
while (my ($cpu, $load) = each(%$cpus)) {
123
print "cpu$cpu.value $load\n";
134
my $ret = $oid . "0";
137
print "# Starting browse of $oid...\n" if $DEBUG;
143
print "# Checking for $ret...\n" if $DEBUG;
144
$response = $handle->get_request ($ret);
146
if ($num or !defined $response)
148
print "# Checking for sibling of $ret...\n" if $DEBUG;
149
$response = $handle->get_next_request ($ret);
155
my @keys = keys %$response;
157
print "# Analyzing $ret (compared to $oid)...\n" if $DEBUG;
158
last unless ($ret =~ /^$oid/);
160
next unless ($response->{$ret} =~ /$regex/);
161
@keys = split (/\./, $ret);
162
$result->{$keys[-1]} = $response->{$ret};;
163
print "# Index $num: ", $keys[-1], " (", $response->{$ret}, ")\n" if $DEBUG;