| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Getopt::Long qw(:config no_ignore_case); #bundling | ||
| 6 | use Pod::Usage; | ||
| 7 | |||
| 8 | use Cisco::SNMP::CPU; | ||
| 9 | |||
| 10 | my %opt; | ||
| 11 | my ($opt_help, $opt_man); | ||
| 12 | |||
| 13 | GetOptions( | ||
| 14 | 'community=s' => \$opt{community}, | ||
| 15 | 'help!' => \$opt_help, | ||
| 16 | 'man!' => \$opt_man | ||
| 17 | ) or pod2usage(-verbose => 0); | ||
| 18 | |||
| 19 | pod2usage(-verbose => 1) if defined $opt_help; | ||
| 20 | pod2usage(-verbose => 2) if defined $opt_man; | ||
| 21 | |||
| 22 | # Make sure at least one arg was provided | ||
| 23 | if (!@ARGV) { | ||
| 24 | pod2usage(-verbose => 0, -message => "$0: host required\n") | ||
| 25 | } | ||
| 26 | |||
| 27 | $opt{community} = $opt{community} || 'private'; | ||
| 28 | |||
| 29 | for (@ARGV) { | ||
| 30 | print "\n-- $_ --\n"; | ||
| 31 | |||
| 32 | my $cm; | ||
| 33 | if (!defined($cm = Cisco::SNMP::CPU->new( | ||
| 34 | hostname => $_, | ||
| 35 | community => $opt{community} | ||
| 36 | ))) { | ||
| 37 | printf "Error: %s\n", Cisco::SNMP::CPU->error; | ||
| 38 | next | ||
| 39 | } | ||
| 40 | |||
| 41 | if (defined(my $cpu = $cm->cpu_info())) { | ||
| 42 | print "CPU Name | 5 second(%) | 1 minute(%) | 5 minute(%)\n"; | ||
| 43 | print "--------------------|-------------|-------------|------------\n"; | ||
| 44 | for (0..$#{$cpu}) { | ||
| 45 | printf "%-20s|%9.2f |%9.2f |%9.2f\n", | ||
| 46 | $cpu->cpuName($_), | ||
| 47 | $cpu->cpu5sec($_), | ||
| 48 | $cpu->cpu1min($_), | ||
| 49 | $cpu->cpu5min($_) | ||
| 50 | } | ||
| 51 | print "\n" | ||
| 52 | } else { | ||
| 53 | printf "Error: %s\n", Cisco::SNMP::CPU->error | ||
| 54 | } | ||
| 55 | |||
| 56 | $cm->close() | ||
| 57 | } | ||
| 58 | |||
| 59 | __END__ |