Révision ba4e18a6
Initial version
| plugins/other/cirix-netscaler-cpu-usage | ||
|---|---|---|
| 1 |
#!/usr/bin/perl |
|
| 2 |
# -*- perl -*- |
|
| 3 |
# ---------------------------------------------------- # |
|
| 4 |
# File : netscaler_cpu |
|
| 5 |
# Author: Sandro Wefel |
|
| 6 |
# based on Script by Damien SIAUD |
|
| 7 |
# Date : 05/05/2011 |
|
| 8 |
# Modified : 05/05/2011 |
|
| 9 |
# ---------------------------------------------------- # |
|
| 10 |
# This script require Net::SNMP |
|
| 11 |
# |
|
| 12 |
# Netscaler plugin for munin |
|
| 13 |
# |
|
| 14 |
# License Information: |
|
| 15 |
# This program is free software; you can redistribute it and/or modify |
|
| 16 |
# it under the terms of the GNU General Public License as published by |
|
| 17 |
# the Free Software Foundation; either version 3 of the License, or |
|
| 18 |
# (at your option) any later version. |
|
| 19 |
# |
|
| 20 |
# This program is distributed in the hope that it will be useful, |
|
| 21 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 22 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 23 |
# GNU General Public License for more details. |
|
| 24 |
# |
|
| 25 |
# You should have received a copy of the GNU General Public License |
|
| 26 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 27 |
# |
|
| 28 |
# ---------------------------------------------------- # |
|
| 29 |
|
|
| 30 |
=head1 NAME |
|
| 31 |
|
|
| 32 |
netscaler_cpu - Munin plugin to monitor CPU usage |
|
| 33 |
|
|
| 34 |
=head1 CONFIGURATION |
|
| 35 |
|
|
| 36 |
Make a symlink from netscaler_cpu_ to /etc/munin/plugins/netscaler_cpu_<nsfqdn>. |
|
| 37 |
You can omit <nsfqdn>, then you need the env variable B<host>. |
|
| 38 |
|
|
| 39 |
To configure the plugin, use ENV variables. |
|
| 40 |
|
|
| 41 |
Add something lile this to /etc/munin/plugin-conf.d/<conf> |
|
| 42 |
[netscaler_cpu_*] |
|
| 43 |
env.community CommunityName |
|
| 44 |
|
|
| 45 |
Variables: |
|
| 46 |
|
|
| 47 |
=over |
|
| 48 |
|
|
| 49 |
=item ENV B<host> netscaler host as FQDN or IP I<default is the nsfqdn-suffix from pluginname> |
|
| 50 |
|
|
| 51 |
=item ENV B<port> I<default 161> |
|
| 52 |
|
|
| 53 |
=item ENV B<community> I<default "public"> |
|
| 54 |
|
|
| 55 |
=item ENV B<timeout> in seconds I<default 5> |
|
| 56 |
|
|
| 57 |
=back |
|
| 58 |
|
|
| 59 |
=head1 AUTHORS |
|
| 60 |
|
|
| 61 |
=over |
|
| 62 |
|
|
| 63 |
=item Sandro Wefel <wefel@unixos.de> |
|
| 64 |
|
|
| 65 |
=item based on scripts by Jimmy Olsen, Damien SIAUD |
|
| 66 |
|
|
| 67 |
=back |
|
| 68 |
|
|
| 69 |
=head1 LICENSE |
|
| 70 |
|
|
| 71 |
GNU General Public License |
|
| 72 |
|
|
| 73 |
=head1 MAGIC MARKERS |
|
| 74 |
|
|
| 75 |
#%# family=auto |
|
| 76 |
#%# capabilities=autoconf |
|
| 77 |
|
|
| 78 |
=cut |
|
| 79 |
|
|
| 80 |
use Net::SNMP; |
|
| 81 |
|
|
| 82 |
use Munin::Plugin; |
|
| 83 |
|
|
| 84 |
use vars qw($script_name $script_version $o_host $o_community $o_port $o_timeout); |
|
| 85 |
|
|
| 86 |
use strict; |
|
| 87 |
|
|
| 88 |
|
|
| 89 |
# --------------------------- globals -------------------------- # |
|
| 90 |
|
|
| 91 |
$script_name = "netscaler_cpu"; |
|
| 92 |
$script_version = "0.1"; |
|
| 93 |
|
|
| 94 |
$o_host = undef; |
|
| 95 |
$o_community = undef; |
|
| 96 |
$o_port = 161; |
|
| 97 |
|
|
| 98 |
my $return_str = ""; |
|
| 99 |
my @cpu_name = (); |
|
| 100 |
|
|
| 101 |
|
|
| 102 |
# ---------------------------- snmp ---------------------------- # |
|
| 103 |
|
|
| 104 |
my $oid_prefix = "1.3.6.1.4.1.5951"; |
|
| 105 |
my $oid_build_version = $oid_prefix.".4.1.1.1.0"; |
|
| 106 |
my $oid_avgcpu_usage = $oid_prefix.".4.1.1.41.1.0"; # cpu utilization (%) |
|
| 107 |
my $oid_cpu_name = $oid_prefix.".4.1.1.41.6.1.1"; # name of cpu in NetScaler |
|
| 108 |
my $oid_cpu_usage = $oid_prefix.".4.1.1.41.6.1.2"; # usage per cpu (%) |
|
| 109 |
|
|
| 110 |
# ---------------------------- main ----------------------------- # |
|
| 111 |
|
|
| 112 |
|
|
| 113 |
my $DEBUG = 0; |
|
| 114 |
|
|
| 115 |
my $o_host = $ENV{host} || undef;
|
|
| 116 |
my $o_port = $ENV{port} || 161;
|
|
| 117 |
my $o_community = $ENV{community} || "public";
|
|
| 118 |
my $o_timeout = $ENV{timeout} || 5;
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
|
|
| 122 |
print "yes\n"; |
|
| 123 |
exit 0; |
|
| 124 |
} |
|
| 125 |
|
|
| 126 |
if (! defined $o_host ) {
|
|
| 127 |
$0 =~ /netscaler_cpu_(.+)*$/; |
|
| 128 |
$o_host = $1; |
|
| 129 |
die "No host provided" unless defined $o_host; |
|
| 130 |
} |
|
| 131 |
|
|
| 132 |
# open session |
|
| 133 |
my $session = &open_session(); |
|
| 134 |
if (!defined($session)) {
|
|
| 135 |
print "ERROR opening session\n"; |
|
| 136 |
exit 1; |
|
| 137 |
} |
|
| 138 |
|
|
| 139 |
# CPU names |
|
| 140 |
if (&get_cpus($session) lt 1) {
|
|
| 141 |
print "ERROR getting number of CPUs\n"; |
|
| 142 |
exit 1; |
|
| 143 |
}; |
|
| 144 |
|
|
| 145 |
if ($ARGV[0] and $ARGV[0] eq "config") {
|
|
| 146 |
print "graph_args --base 1024 -l 0 --upper-limit 100\n"; |
|
| 147 |
print "graph_vlabel %\n"; |
|
| 148 |
print "graph_scale no\n"; |
|
| 149 |
print "graph_title CPU usage for $o_host\n"; |
|
| 150 |
print "graph_category netscaler\n"; |
|
| 151 |
print "graph_period second\n"; |
|
| 152 |
print "graph_info This graph shows how CPU time is spent.\n"; |
|
| 153 |
print "avg.label avg\n"; |
|
| 154 |
print "avg.draw AREA\n"; |
|
| 155 |
print "avg.info Average load.\n"; |
|
| 156 |
foreach my $v (@cpu_name){
|
|
| 157 |
print $v.".label ".$v."\n"; |
|
| 158 |
print $v.".draw LINE2\n"; |
|
| 159 |
print $v.".info CPU usage of ".$v."\n"; |
|
| 160 |
print_thresholds($v); |
|
| 161 |
} |
|
| 162 |
|
|
| 163 |
for my $field qw(avg) {
|
|
| 164 |
print_thresholds($field); |
|
| 165 |
} |
|
| 166 |
&close_session($session); |
|
| 167 |
exit 0; |
|
| 168 |
} |
|
| 169 |
|
|
| 170 |
|
|
| 171 |
# Average |
|
| 172 |
&get_avgcpu_usage($session); |
|
| 173 |
# per CPU usage |
|
| 174 |
&get_cpu_usage($session); |
|
| 175 |
|
|
| 176 |
|
|
| 177 |
&close_session($session); |
|
| 178 |
|
|
| 179 |
print "$return_str"; |
|
| 180 |
exit 0; |
|
| 181 |
|
|
| 182 |
# --------------------------- functions ------------------------- # |
|
| 183 |
|
|
| 184 |
sub open_session {
|
|
| 185 |
my ($sess, $str) = Net::SNMP->session( |
|
| 186 |
-hostname => $o_host, |
|
| 187 |
-community => $o_community, |
|
| 188 |
-port => $o_port, |
|
| 189 |
-timeout => $o_timeout |
|
| 190 |
); |
|
| 191 |
|
|
| 192 |
$return_str = $str; |
|
| 193 |
|
|
| 194 |
return $sess; |
|
| 195 |
} |
|
| 196 |
|
|
| 197 |
|
|
| 198 |
sub close_session {
|
|
| 199 |
my ($sess) = @_; |
|
| 200 |
|
|
| 201 |
if(defined($sess)){
|
|
| 202 |
$session->close; |
|
| 203 |
} |
|
| 204 |
} |
|
| 205 |
|
|
| 206 |
sub get_buildversion {
|
|
| 207 |
my ($session) = @_; |
|
| 208 |
my $build_version; |
|
| 209 |
|
|
| 210 |
my $result = $session->get_request( |
|
| 211 |
-varbindlist => [$oid_build_version] |
|
| 212 |
); |
|
| 213 |
|
|
| 214 |
if (!defined($result)) {
|
|
| 215 |
return "na"; |
|
| 216 |
} |
|
| 217 |
else {
|
|
| 218 |
$build_version = $result->{$oid_build_version};
|
|
| 219 |
return"Build version : ".$build_version; |
|
| 220 |
} |
|
| 221 |
} |
|
| 222 |
|
|
| 223 |
|
|
| 224 |
sub get_avgcpu_usage {
|
|
| 225 |
my ($session) = @_; |
|
| 226 |
my $cpu_usage; |
|
| 227 |
|
|
| 228 |
my $result = $session->get_request( |
|
| 229 |
-varbindlist => [$oid_avgcpu_usage] |
|
| 230 |
); |
|
| 231 |
|
|
| 232 |
if (!defined($result)) {
|
|
| 233 |
$return_str = "na"; |
|
| 234 |
} |
|
| 235 |
else {
|
|
| 236 |
$cpu_usage = $result->{$oid_avgcpu_usage};
|
|
| 237 |
$return_str .= "avg.value ".$cpu_usage."\n"; |
|
| 238 |
} |
|
| 239 |
|
|
| 240 |
} |
|
| 241 |
|
|
| 242 |
sub get_cpu_usage {
|
|
| 243 |
my ($session) = @_; |
|
| 244 |
my %cpu_usage; |
|
| 245 |
|
|
| 246 |
my $index=0; |
|
| 247 |
my $result = $session->get_table(-baseoid => $oid_cpu_usage); |
|
| 248 |
|
|
| 249 |
if (!defined($result)) {
|
|
| 250 |
return "na"; |
|
| 251 |
} |
|
| 252 |
else {
|
|
| 253 |
foreach my $v ($session->var_bind_names()){
|
|
| 254 |
$cpu_usage{$cpu_name[$index]} = $session->var_bind_list()->{$v};
|
|
| 255 |
$return_str .= $cpu_name[$index] . ".value ".$cpu_usage{$cpu_name[$index]}."\n";
|
|
| 256 |
$index++; |
|
| 257 |
} |
|
| 258 |
} |
|
| 259 |
} |
|
| 260 |
|
|
| 261 |
sub get_cpus {
|
|
| 262 |
my ($session) = @_; |
|
| 263 |
my %cpu_usage; |
|
| 264 |
|
|
| 265 |
my $result = $session->get_table(-baseoid => $oid_cpu_name); |
|
| 266 |
|
|
| 267 |
if (!defined($result)) {
|
|
| 268 |
return 0; |
|
| 269 |
} |
|
| 270 |
else {
|
|
| 271 |
@cpu_name = (); |
|
| 272 |
foreach my $n ($session->var_bind_names()) {
|
|
| 273 |
push @cpu_name, $session->var_bind_list()->{$n};
|
|
| 274 |
} |
|
| 275 |
|
|
| 276 |
} |
|
| 277 |
|
|
| 278 |
my $number=@cpu_name; |
|
| 279 |
return $number; |
|
| 280 |
} |
|
Formats disponibles : Unified diff