BIG-IP Multi Host CPU Monitor

Problem this snippet solves:

This script polls the BIG-IP via SNMP and displays the current CPU utilization for each processor and the global utilization for all processors.

How to use this snippet:

  1. Install script on remote system with appropriate permissions.
  2. Make sure Perl and the Net::SNMP perl module are installed.

Code :

#!/usr/bin/perl -w
# This code is not supported by F5 Network and is offered under the GNU General Public License.  Use at your own risk.

use strict;
use Net::SNMP qw(:snmp);

my ($host, $snmp_comm);

$host = $ARGV[0];
$snmp_comm = $ARGV[1];
chomp ($host , $snmp_comm);

my $cpuIndex     = ".1.3.6.1.4.1.3375.2.1.7.5.2.1.2.1.48";

my $cpuUsageRatio5s = ".1.3.6.1.4.1.3375.2.1.7.5.2.1.19.1.48.";
my $cpuUsageRatio1m = ".1.3.6.1.4.1.3375.2.1.7.5.2.1.27.1.48.";
my $cpuUsageRatio5m = ".1.3.6.1.4.1.3375.2.1.7.5.2.1.35.1.48.";

my $gcpuUsageRatio5s = ".1.3.6.1.4.1.3375.2.1.1.2.20.21.0";
my $gcpuUsageRatio1m = ".1.3.6.1.4.1.3375.2.1.1.2.20.29.0";
my $gcpuUsageRatio5m = ".1.3.6.1.4.1.3375.2.1.1.2.20.37.0";

my ($session, $error) = Net::SNMP->session(
            -hostname       => $host,
            -community      => $snmp_comm,
            -port           => 161,
            -version        => 'snmpv2c',
            -nonblocking    => 0
            );

if (!defined $session) {
        print "Received no SNMP response from $host\n";
        print STDERR "Error: $error\n";
        exit -1;
        }
    
my $allCPU = $session->get_table ( -baseoid => $cpuIndex );
my %cpu_table = %{$allCPU};
my $x = 0;

print "\n\nCPU Utilization:\t5s\t1m\t5m\n\n";

foreach my $key (sort keys %cpu_table) {
my @oid_index = split(/\./, $key);
my $ltm_cpu5s = $cpuUsageRatio5s . $oid_index[-1];
my $ltm_cpu1m = $cpuUsageRatio1m . $oid_index[-1];
my $ltm_cpu5m = $cpuUsageRatio5m . $oid_index[-1];

my $oid_ratios = $session->get_request(
-varbindlist =>
[$ltm_cpu5s, $ltm_cpu1m, $ltm_cpu5m] );

print "\tCPU$x\t\t$oid_ratios->{$ltm_cpu5s}\t$oid_ratios->{$ltm_cpu1m}\t$oid_ratios->{$ltm_cpu5m}\n";

$x++;
}

my $oid_gratios = $session->get_request(
-varbindlist =>
[$gcpuUsageRatio5s, $gcpuUsageRatio1m, $gcpuUsageRatio5m] );

print "\tGlobal\t\t$oid_gratios->{$gcpuUsageRatio5s}\t$oid_gratios->{$gcpuUsageRatio1m}\t$oid_gratios->{$gcpuUsageRatio5m}\n\n\n";
Published Mar 12, 2015
Version 1.0
  • Hi,

     

    This is great but I'm getting an error at the same time I get the values, so Cacti will not generate graphs...

     

    The error is:

     

    Use of uninitialized value $allCPU in hash dereference at /usr/share/cacti/scripts/f5_bigip_cpun.pl line 39.

     

    Can you help?

     

    Thanks and regards, jtimartins