root / plugins / snmp / snmp__cpu @ 7da1b039
Historique | Voir | Annoter | Télécharger (2,4 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# |
| 3 |
# Copyright (C) 2006 Lars Strand |
| 4 |
# |
| 5 |
# Munin plugin to monitor CPU-load by use of SNMP. |
| 6 |
# Based on snmp__df plugin. |
| 7 |
# |
| 8 |
# This program is free software; you can redistribute it and/or |
| 9 |
# modify it under the terms of the GNU General Public License |
| 10 |
# as published by the Free Software Foundation; version 2 dated June, |
| 11 |
# 1991. |
| 12 |
# |
| 13 |
# This program is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program; if not, write to the Free Software |
| 20 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 |
# |
| 22 |
# $Log$ |
| 23 |
# |
| 24 |
# |
| 25 |
# |
| 26 |
#%# family=snmpauto |
| 27 |
#%# capabilities=snmpconf |
| 28 |
|
| 29 |
use strict; |
| 30 |
use Net::SNMP; |
| 31 |
|
| 32 |
my $DEBUG = 0; |
| 33 |
|
| 34 |
my $host = $ENV{host} || undef;
|
| 35 |
my $port = $ENV{port} || 161;
|
| 36 |
my $community = $ENV{community} || "public";
|
| 37 |
|
| 38 |
my $response; |
| 39 |
|
| 40 |
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") |
| 41 |
{
|
| 42 |
print "index 1.3.6.1.2.1.25.3.3.1.2.\n"; |
| 43 |
print "require 1.3.6.1.2.1.25.3.3.1.2.1\n"; # CPU #1 |
| 44 |
exit 0; |
| 45 |
} |
| 46 |
|
| 47 |
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_cpu$/) |
| 48 |
{
|
| 49 |
$host = $1; |
| 50 |
if ($host =~ /^([^:]+):(\d+)$/) |
| 51 |
{
|
| 52 |
$host = $1; |
| 53 |
$port = $2; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
elsif (!defined($host)) |
| 58 |
{
|
| 59 |
print "# Debug: $0 -- $1\n" if $DEBUG; |
| 60 |
die "# Error: couldn't understand what I'm supposed to monitor."; |
| 61 |
} |
| 62 |
|
| 63 |
my ($session, $error) = Net::SNMP->session( |
| 64 |
-hostname => $host, |
| 65 |
-community => $community, |
| 66 |
-port => $port |
| 67 |
); |
| 68 |
|
| 69 |
if (!defined ($session)) |
| 70 |
{
|
| 71 |
die "Croaking: $error"; |
| 72 |
} |
| 73 |
|
| 74 |
# CPUs |
| 75 |
my $hrProcessorLoad = "1.3.6.1.2.1.25.3.3.1.2."; |
| 76 |
$response = $session->get_table($hrProcessorLoad); |
| 77 |
|
| 78 |
if (!defined ($response)) |
| 79 |
{
|
| 80 |
die "Croaking: $error"; |
| 81 |
} |
| 82 |
|
| 83 |
if (defined $ARGV[0] and $ARGV[0] eq "config") |
| 84 |
{
|
| 85 |
print "host_name $host\n"; |
| 86 |
print "graph_title CPU usage (in %) |
| 87 |
graph_category system |
| 88 |
graph_args --upper-limit 100 -l 0 |
| 89 |
graph_vlabel % |
| 90 |
graph_info This graph shows the CPU load on the system. |
| 91 |
"; |
| 92 |
foreach my $cpuoid (keys %$response) {
|
| 93 |
my @oid = split(/\./, $cpuoid); |
| 94 |
my $cpu = pop @oid; |
| 95 |
print "cpu$cpu.label CPU $cpu\n"; |
| 96 |
print "cpu$cpu.info CPU load on CPU $cpu\n"; |
| 97 |
} |
| 98 |
exit 0; |
| 99 |
} |
| 100 |
|
| 101 |
# the values |
| 102 |
while (my ($cpuoid, $load) = each(%$response)) {
|
| 103 |
my @oid = split(/\./, $cpuoid); |
| 104 |
my $cpu = pop @oid; |
| 105 |
print "cpu$cpu.value $load\n"; |
| 106 |
} |
| 107 |
|
