Forum Discussion

banjoooooooooo_'s avatar
banjoooooooooo_
Icon for Nimbostratus rankNimbostratus
Oct 08, 2008

Cpu and TMM monitor script

Hmm... I've been trying today to get the same results as the graphs in the TMUI for CPU and TMM usage I'm not sure why I'm getting different results and I noticed the results with my scripts below is bigger than whats in the TMUI stats... anyone could have a third look? Here's my script

 
 !/usr/bin/perl 
  
  Usage: tmm-and-cpu.pl   
  
  
 use Net::SNMP qw(:snmp); 
  
 my $host = $ARGV[0]; 
 my $snmp_comm = $ARGV[1]; 
 chomp $host; 
 chomp $snmp_comm; 
  
  
 CPU Usage Definitions 
 my $cpuSysHostCpuUser    = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.3.1'; 
 my $cpuSysHostCpuNice    = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.4.1'; 
 my $cpuSysHostCpuIdle    = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.5.1'; 
 my $cpuSysHostCpuSyst    = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.6.1'; 
 my $cpuSysHostCpuIrq     = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.7.1'; 
 my $cpuSysHostCpuSoftIrq = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.8.1'; 
 my $cpuSysHostCpuIoWait  = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.9.1'; 
  
 TMM Usage Definitions 
 my $tmmTotalCyl = '.1.3.6.1.4.1.3375.2.1.1.2.1.41.0'; 
 my $tmmIdleCyl = '.1.3.6.1.4.1.3375.2.1.1.2.1.42.0'; 
 my $tmmSleepCyl = '.1.3.6.1.4.1.3375.2.1.1.2.1.43.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; 
         } 
  
  poll CPU oids for Delta Calculations 
 my $cpu_oids_0 = $session->get_request( 
                   -varbindlist => 
                   [$cpuSysHostCpuUser, $cpuSysHostCpuNice, $cpuSysHostCpuIdle, $cpuSysHostCpuSyst, $cpuSysHostCpuIrq, $cpuSysHostCpuSoftIrq, $cpuSysHostCpuIoWait] ); 
  
 sleep 10; 
  
 my $cpu_oids_1 = $session->get_request( 
                   -varbindlist => 
                   [$cpuSysHostCpuUser, $cpuSysHostCpuNice, $cpuSysHostCpuIdle, $cpuSysHostCpuSyst, $cpuSysHostCpuIrq, $cpuSysHostCpuSoftIrq, $cpuSysHostCpuIoWait] ); 
  
  
  
  poll TMM oids for Delta Calculations 
 my $tmm_oids_0 = $session->get_request( 
                   -varbindlist => 
                   [$tmmTotalCyl, $tmmIdleCyl, $tmmSleepCyl] ); 
  
 sleep 10; 
  
 my $tmm_oids_1 = $session->get_request( 
                   -varbindlist => 
                   [$tmmTotalCyl, $tmmIdleCyl, $tmmSleepCyl] ); 
  
  
  CPU Deltas 
 my $DeltaCpuUser    = $cpu_oids_0->{$cpuSysHostCpuUser} - $cpu_oids_1->{$cpuSysHostCpuUser}; 
 my $DeltaCpuNice    = $cpu_oids_0->{$cpuSysHostCpuNice} - $cpu_oids_1->{$cpuSysHostCpuNice}; 
 my $DeltaCpuIdle    = $cpu_oids_0->{$cpuSysHostCpuIdle} - $cpu_oids_1->{$cpuSysHostCpuIdle}; 
 my $DeltaCpuSyst    = $cpu_oids_0->{$cpuSysHostCpuSyst} - $cpu_oids_1->{$cpuSysHostCpuSyst}; 
 my $DeltaCpuIrq     = $cpu_oids_0->{$cpuSysHostCpuIrq}  - $cpu_oids_1->{$cpuSysHostCpuIrq}; 
 my $DeltaSoftIrq    = $cpu_oids_0->{$cpuSysHostCpuSoftIrq}  - $cpu_oids_1->{$cpuSysHostCpuSoftIrq}; 
 my $DeltaCpuIoWait  = $cpu_oids_0->{$cpuSysHostCpuIoWait}  - $cpu_oids_1->{$cpuSysHostCpuIoWait}; 
  
  TMM Deltas 
 my $DeltaTotalCyl = $tmm_oids_0->{$tmmTotalCyl} - $tmm_oids_1->{$tmmTotalCyl}; 
 my $DeltaIdleCyl  = $tmm_oids_0->{$tmmIdleCyl} - $tmm_oids_1->{$tmmIdleCyl}; 
 my $DeltaSleepCyl = $tmm_oids_0->{$tmmSleepCyl} - $tmm_oids_1->{$tmmSleepCyl}; 
  
 my $CpuUsage = ( ( $DeltaCpuUser + $DeltaCpuNice + $DeltaCpuSystem )  /  ( $DeltaCpuUser + $DeltaCpuNice + $DeltaCpuIdle + $DeltaCpuSyst + $DeltaCpuIrq + $DeltaSoftIrq + $DeltaCpuIoWait ) * 100 ); 
 my $TmmCpuUsage = ((($DeltaTotalCyl - ( $DeltaIdleCyl + $DeltaSleepCyl )) / $DeltaTotalCyl ) * 100 ); 
  
 $CpuUsage = int($CpuUsage + .5); 
 $TmmCpuUsage = int($TmmCpuUsage + .5); 
  
 print $CpuUsage; 
 print "\n".$TmmCpuUsage; 
  
  
  
 

This calculations are based on the latest NSM for BIG-IP.

Thanks!!!

7 Replies

  • I pipe the output of the script into Cacti for graphing purposes.

     

     

    Here is what I use for the host cpu script:

     

     

    $ more f5-bigip-host-cpu.pl

     

    !/usr/bin/perl

     

    Host CPU Monitor Script

     

    This works for 2 Processor Boxes, running 9.3.x

     

    There is a new method for 2 Processor Boxes, running 9.4.x

     

     

    Usage: f5-bigip-host-cpu.pl

     

     

     

    use Net::SNMP qw(:snmp);

     

     

    my $host = $ARGV[0];

     

    my $snmp_comm = $ARGV[1];

     

    chomp $host;

     

    chomp $snmp_comm;

     

     

    my $User = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.3.1';

     

    my $Nice = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.4.1';

     

    my $System = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.5.1';

     

    my $IdleCyl = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.6.1';

     

    my $IrqCyl = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.7.1';

     

    my $SoftIrq = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.8.1';

     

    my $IoWait = '.1.3.6.1.4.1.3375.2.1.7.2.2.1.9.1';

     

     

     

    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;

     

    }

     

     

    poll CPU oids

     

     

    my $polled_oids_0 = $session->get_request(

     

    -varbindlist =>

     

    [$User, $Nice, $System, $IdleCyl, $IrqCyl, $SoftIrq, $IoWait]

     

    );

     

     

    sleep 10;

     

    my $polled_oids_1 = $session->get_request(

     

    -varbindlist =>

     

    [$User, $Nice, $System, $IdleCyl, $IrqCyl, $SoftIrq, $IoWait]

     

    );

     

    Calculate Delta

     

    $Nice = ($polled_oids_1->{$Nice} - $polled_oids_0->{$Nice});

     

    $System = ($polled_oids_1->{$System} - $polled_oids_0->{$System});

     

    $User = ($polled_oids_1->{$User} - $polled_oids_0->{$User});

     

    $IdleCyl = ($polled_oids_1->{$IdleCyl} - $polled_oids_0->{$IdleCyl});

     

    $IrqCyl = ($polled_oids_1->{$IrqCyl} - $polled_oids_0->{$IrqCyl});

     

    $SoftIrq = ($polled_oids_1->{$SoftIrq} - $polled_oids_0->{$SoftIrq});

     

    $IoWait = ($polled_oids_1->{$IoWait} - $polled_oids_0->{$IoWait});

     

     

     

    calculate CPU Utilization

     

    my $cpu = ((($Nice + $User + $System) / ($Nice + $User + $System + $IdleCyl + $I

     

    rqCyl + $SoftIrq + $IoWait)) * 100);

     

     

     

    Round to integer

     

    $cpu = int;

     

     

    print CPU Utilization to stdout for cli validation

     

    print $cpu;

     

  • Here is what I use for the TMM CPU:

     

     

    $ more f5-bigip-tmm-cpu.pl

     

    !/usr/bin/perl

     

     

    Usage: f5-bigip-tmm-cpu.pl

     

     

     

    use Net::SNMP qw(:snmp);

     

     

    my $host = $ARGV[0];

     

    my $snmp_comm = $ARGV[1];

     

    chomp $host;

     

    chomp $snmp_comm;

     

     

    my $tmmTotalCyl = '.1.3.6.1.4.1.3375.2.1.1.2.1.41.0';

     

    my $tmmIdleCyl = '.1.3.6.1.4.1.3375.2.1.1.2.1.42.0';

     

    my $tmmSleepCyl = '.1.3.6.1.4.1.3375.2.1.1.2.1.43.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;

     

    }

     

     

    poll CPU oids

     

     

    my $polled_oids_0 = $session->get_request(

     

    -varbindlist =>

     

    [$tmmTotalCyl, $tmmIdleCyl, $tmmSleepCyl] );

     

     

    sleep 10;

     

    my $polled_oids_1 = $session->get_request(

     

    -varbindlist =>

     

    [$tmmTotalCyl, $tmmIdleCyl, $tmmSleepCyl] );

     

     

     

    calculate CPU Utilization

     

    my $tmm_cpu = (( ($polled_oids_1->{$tmmTotalCyl} - $polled_oids_0->{$tmmTotalCyl

     

    }) -

     

    ( ($polled_oids_1->{$tmmIdleCyl} - $polled_oids_0->{$tmmIdleCyl}

     

    ) +

     

    ($polled_oids_1->{$tmmSleepCyl} - $polled_oids_0->{$tmmSleepCyl}

     

    ) ))

     

    / ($polled_oids_1->{$tmmTotalCyl} - $polled_oids_0->{$tmmTotalCy

     

    l}) ) * 100 ;

     

     

    Round to integer

     

    $tmm_cpu = int($tmm_cpu + .5);

     

     

    print CPU Utilization to stdout for cli validation

     

    print $tmm_cpu;

     

  • For 9.4.x if you want to get the CPU % Utilized all you need for the host is this SNMP OID: .1.3.6.1.4.1.3375.2.1.7.5.2.1.11.1.49.1
  • Hi

     

     

    i had problem with these lines in script

     

    my $host = $ARGVΎ]

     

    my $snmp_comm = $ARGVΏ]

     

     

    is that correct

     

     

    and i saw oid for cpu usage, when i look the ask.f5.com i see alot of parameters and calculation and these last message gives me cpu usage

     

     

    snmpwalk -c public -v 2c 192.168.0.120 .1.3.6.1.4.1.3375.2.1.7.5.2.1.11.1.49.1

     

    SNMPv2-SMI::enterprises.3375.2.1.7.5.2.1.11.1.49.1 = Counter64: 5

     

     

    so is that possible to give me oid numbers for version 9.4.5

     

    i had oid numbers from support guys and tech.f5.com but it does not give what i wants

     

     

    i want see Cpu usage (host and tmm)

     

    memory usage and interfaces usage

     

     

    regards

     

     

    Zafer
  • hi, i'm running 9.3.1. i copied your script for cpu utilization (f5-bigip-tmm-cpu.pl).

     

    these are the message I'm getting. any suggestions?

     

    12/11/2008 05:25:22 PM - SPINE: Poller[0] Host[103] ERROR: Empty result [10.4.224.28]: 'perl /usr/share/cacti/site/scripts/f5-bigip-tmm-cpu.pl 10.4.224.28 d1n&0l1n&'

     

    12/11/2008 05:25:22 PM - SPINE: Poller[0] Host[103] DS[1813] WARNING: Result from SCRIPT not valid. Partial Result: ...

     

    12/11/2008 05:25:22 PM - SPINE: Poller[0] Host[103] ERROR: Empty result [10.4.224.28]: 'perl /usr/share/cacti/site/scripts/f5-bigip-tmm-cpu.pl 10.4.224.28 d1n&0l1n&'

     

    12/11/2008 05:25:22 PM - SPINE: Poller[0] Host[103] DS[1250] WARNING: Result from SCRIPT not valid. Partial Result: ...

     

    12/11/2008 05:25:22 PM - SPINE: Poller[0] Host[103] ERROR: Empty result [10.4.224.28]: 'perl /usr/share/cacti/site/scripts/f5-bigip-tmm-cpu.pl 10.4.224.28 d1n&0l1n&'