root / plugins / snmp / snmp_zyxel_usg__cpu @ 7da1b039
Historique | Voir | Annoter | Télécharger (3,56 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# |
| 3 |
# Copyright (C) 2009 Branislav Bozgai |
| 4 |
# |
| 5 |
# Munin plugin to monitor ZyXel USG series routers CPU utilization. |
| 6 |
# Based on snmp__if_ 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 |
|
| 23 |
#%# family=snmpauto |
| 24 |
#%# capabilities=snmpconf |
| 25 |
|
| 26 |
use strict; |
| 27 |
use Net::SNMP; |
| 28 |
|
| 29 |
my $DEBUG = 0; |
| 30 |
|
| 31 |
my $host = $ENV{host} || undef;
|
| 32 |
my $port = $ENV{port} || 161;
|
| 33 |
my $community = $ENV{community} || "public";
|
| 34 |
|
| 35 |
my $response; |
| 36 |
|
| 37 |
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") |
| 38 |
{
|
| 39 |
print "require 1.3.6.1.4.1.890.1.6.22.1.1.0 \n"; |
| 40 |
exit 0; |
| 41 |
} |
| 42 |
|
| 43 |
if ($0 =~ /^(?:|.*\/)snmp_zyxel_usg_([^_]+)_cpu$/) |
| 44 |
{
|
| 45 |
$host = $1; |
| 46 |
if ($host =~ /^([^:]+):(\d+)$/) |
| 47 |
{
|
| 48 |
$host = $1; |
| 49 |
$port = $2; |
| 50 |
} |
| 51 |
} |
| 52 |
elsif (!defined($host)) |
| 53 |
{
|
| 54 |
print "# Debug: $0 -- $1\n" if $DEBUG; |
| 55 |
die "# Error: couldn't understand what I'm supposed to monitor."; |
| 56 |
} |
| 57 |
|
| 58 |
my $sysCPUUsage = "1.3.6.1.4.1.890.1.6.22.1.1.0"; |
| 59 |
my $sysCPU5SecUsage = "1.3.6.1.4.1.890.1.6.22.1.3.0"; |
| 60 |
my $sysCPU1MinUsage = "1.3.6.1.4.1.890.1.6.22.1.4.0"; |
| 61 |
my $sysCPU5MinUsage = "1.3.6.1.4.1.890.1.6.22.1.5.0"; |
| 62 |
|
| 63 |
my ($session, $error) = Net::SNMP->session( |
| 64 |
-hostname => $host, |
| 65 |
-community => $community, |
| 66 |
-port => $port |
| 67 |
); |
| 68 |
|
| 69 |
|
| 70 |
if (!defined ($session)) |
| 71 |
{
|
| 72 |
die "Croaking: $error"; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
if ($ARGV[0] and $ARGV[0] eq "config") |
| 77 |
{
|
| 78 |
print "host_name $host\n"; |
| 79 |
if (!defined ($response = $session->get_request($sysCPUUsage))) |
| 80 |
{
|
| 81 |
die "Croaking: " . $session->error(); |
| 82 |
} |
| 83 |
print "graph_title CPU usage\n"; |
| 84 |
print "graph_category system\n"; |
| 85 |
print "graph_args --base 1000 -r --lower-limit 0 --upper-limit 100\n"; |
| 86 |
print "graph_vlabel %\n"; |
| 87 |
print "graph_scale no\n"; |
| 88 |
print "graph_period second\n"; |
| 89 |
print "graph_info CPU usage\n"; |
| 90 |
print "sysCPUUsage.label CPU Usage\n"; |
| 91 |
print "sysCPU5SecUsage.label CPU 5 sec Avg Usage\n"; |
| 92 |
print "sysCPU1MinUsage.label CPU 1 min Avg Usage\n"; |
| 93 |
print "sysCPU5MinUsage.label CPU 5 min Avg Usage\n"; |
| 94 |
print "sysCPUUsage.draw AREA\n"; |
| 95 |
print "sysCPU5SecUsage.draw AREA\n"; |
| 96 |
print "sysCPU1MinUsage.draw AREA\n"; |
| 97 |
print "sysCPU5MinUsage.draw AREA\n"; |
| 98 |
exit 0; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
if (defined ($response = $session->get_request($sysCPUUsage))) |
| 103 |
{
|
| 104 |
print "sysCPUUsage.value ", $response->{$sysCPUUsage}, "\n";
|
| 105 |
} |
| 106 |
else |
| 107 |
{
|
| 108 |
print "sysCPUUsage.value U\n"; |
| 109 |
} |
| 110 |
|
| 111 |
if (defined ($response = $session->get_request($sysCPU5SecUsage))) |
| 112 |
{
|
| 113 |
print "sysCPU5SecUsage.value ", $response->{$sysCPU5SecUsage}, "\n";
|
| 114 |
} |
| 115 |
else |
| 116 |
{
|
| 117 |
print "sysCPU5SecUsage.value U\n"; |
| 118 |
} |
| 119 |
|
| 120 |
if (defined ($response = $session->get_request($sysCPU1MinUsage))) |
| 121 |
{
|
| 122 |
print "sysCPU1MinUsage.value ", $response->{$sysCPU1MinUsage}, "\n";
|
| 123 |
} |
| 124 |
else |
| 125 |
{
|
| 126 |
print "sysCPU1MinUsage.value U\n"; |
| 127 |
} |
| 128 |
|
| 129 |
if (defined ($response = $session->get_request($sysCPU5MinUsage))) |
| 130 |
{
|
| 131 |
print "sysCPU5MinUsage.value ", $response->{$sysCPU5MinUsage}, "\n";
|
| 132 |
} |
| 133 |
else |
| 134 |
{
|
| 135 |
print "sysCPU5MinUsage.value U\n"; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
# vim:syntax=perl |
