File: snmp__cpuload.in

package info (click to toggle)
munin 2.0.76-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,068 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (110 lines) | stat: -rw-r--r-- 2,384 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!@@PERL@@ -w
# -*- perl -*-
# vim: ft=perl

=head1 NAME

snmp__cpuload - Munin plugin to monitor CPU usage by use of SNMP.

=head1 APPLICABLE SYSTEMS

Any SNMP-capable device that reports the
HOST-RESOURCES-MIB::hrProcessorLoad OID.

=head1 CONFIGURATION

As a rule SNMP plugins need site specific configuration.  The default
configuration (shown here) will only work on insecure sites/devices.

   [snmp_*]
	env.version 2
        env.community public

In general SNMP is not very secure at all unless you use SNMP version
3 which supports authentication and privacy (encryption).  But in any
case the community string for your devices should not be "public".

Please see 'perldoc Munin::Plugin::SNMP' for further configuration
information.

=head1 INTERPRETATION

The average, over the last minute, of the percentage of time that
this processor was not idle.

=head1 MIB INFORMATION

This plugin requires support for the HOST-RESOURCES-MIB (RFC 2790).  It
reports the contents of the hrProcessorLoad OID for each entry in
hrProcessorTable.

=head1 MAGIC MARKERS

  #%# family=snmpauto
  #%# capabilities=snmpconf

=head1 BUGS

None known.

=head1 AUTHOR

Copyright (C) 2006 Lars Strand

Documented and updated to use Munin::Plugin::SNMP by Matthew Boyle.

=head1 LICENSE

GPLv2.

=cut

use strict;
use Munin::Plugin::SNMP;

my $oid = '1.3.6.1.2.1.25.3.3.1.2';

if (defined $ARGV[0] and $ARGV[0] eq 'snmpconf') {
	print "require ${oid}.\n";
	exit 0;
}

my $session = Munin::Plugin::SNMP->session();

my $result = $session->get_entries(-columns => [ $oid ]);

my %cpus;

while (my ($oid, $value) = each %$result) {
	my $index = (split /\./, $oid)[-1];
	$cpus{$index} = $value;
}

if (defined $ARGV[0] and $ARGV[0] eq "config") {
	my $host = $session->hostname;

	print "host_name $host\n" unless ($host eq 'localhost');
	print <<'EOC';
graph_title CPU usage
graph_category system
graph_args --upper-limit 100 -l 0
graph_vlabel %
graph_info This graph shows the CPU load on the system.
EOC
	foreach my $cpu (sort(keys %cpus)) {
		# CPU #1 will have $fieldname "cpu" to retain compatability with
		# old snmp_cpuload plugin.
		my $cpun = $cpu;
		$cpun = '' if $cpun == 1;
		print "cpu$cpun.label CPU $cpu\n";
		print "cpu$cpun.info CPU load on CPU $cpu\n";
	}
	exit 0;
}

# the values
while (my ($cpu, $load) = each(%cpus)) {
	$cpu = '' if $cpu == 1;
	print "cpu$cpu.value $load\n";
}