Forum Discussion

jaskel_40663's avatar
jaskel_40663
Icon for Nimbostratus rankNimbostratus
Feb 05, 2009

Odd issues with SNMP and TMM Usage

I'm using this script (which is floating around in the forums):

 
 !/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 = $session->get_request( 
 -varbindlist => 
 [$tmmTotalCyl, $tmmIdleCyl, $tmmSleepCyl] ); 
  calculate CPU Utilization 
 my $tmm_cpu = (( $polled_oids->{$tmmTotalCyl} - 
 ($polled_oids->{$tmmIdleCyl} + $polled_oids->{$tmmSleepCyl})) 
 / $polled_oids->{$tmmTotalCyl} ) * 100 ; 
  Round to integer 
 $tmm_cpu = int($tmm_cpu + .5); 
  print CPU Utilization to stdout for cli validation 
 print $tmm_cpu; 
 

The odd thing is that is seems to be giving me incorrect values. I've done some traffic moves recently that greatly reduced the TMM CPU usage on one of my nodes, and the Big-IP GUI has correctly noted the change in traffic as has tmstat. Currently the TMM cpu utilization is at about 10%, yet this script through cacti is giving me 54%.

02/04/2009 10:55:04 PM - CMDPHP: Poller[0] Host[28] DS[651] CMD: perl /var/www/cacti/resource/script_queries/f5-bigip-tmm-cpu.pl f5-01a-mgmt sb-snmp, output: 54

Is there anything obvious in this script that would cause this? I've been playing around with it, but I haven't come to anything so far.

Thanks.

-jaskel

4 Replies

  • what version TMOS are you running? This worked pretty well pre-9.4, but I had some issues as well afterwards, but have not gone back and looked at the mibs. I'll add this to my to do list to validate the accuracy.
  • I'm running BIG-IP 9.3.0 Build 194.1. It's very strange. I can see what the node reports and the graph produced by this script seems to be way off.

     

     

    Thanks!

     

     

    -jaskely
  • I borrowed pretty heavily from the original script, but I think I have a version that is a little closer to my reality. I read the docs and found that it needed to have an interval for a delta calculation to get the appropriate. After running this a few times it seems to be pretty much right on with the percentage of TMM CPU utilzation:

     
     !/usr/bin/perl 
      
     use Net::SNMP qw(:snmp); 
      
     my $host = $ARGV[0]; 
     my $snmp_comm = $ARGV[1]; 
      
      
     ($time,$idle,$sleep) = &getValue($host,$snmp_comm); 
     sleep(5); 
     ($time1,$idle1,$sleep1) = &getValue($host,$snmp_comm); 
      
     $time_delta = $time1 - $time; 
     $idle_delta = $idle1 - $idle; 
     $sleep_delta = $sleep1 - $sleep; 
      
     $tmm_usage = (($time_delta - ($idle_delta + $sleep_delta)) / $time_delta )*100; 
     $tmm_usage = int($tmm_usage + .5); 
      
     print "$tmm_usage"; 
      
     sub getValue { 
      
         use Net::SNMP qw(:snmp); 
         my ($host,$snmp_comm) = (@_); 
         my $tmmTotalCycles = '.1.3.6.1.4.1.3375.2.1.1.2.1.41.0'; 
         my $tmmIdleCycles  = '.1.3.6.1.4.1.3375.2.1.1.2.1.42.0'; 
         my $tmmSleepCycles = '.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 "Recieved no SNMP response from $host\n"; 
     print STDERR "Error: $error\n"; 
     exit -1; 
     } 
      
         my $polled_oids = $session->get_request( 
     -varbindlist => [$tmmTotalCycles,$tmmIdleCycles,$tmmSleepCycles] 
     ); 
      
         my $total_time = $polled_oids->{$tmmTotalCycles}; 
         my $total_idle = $polled_oids->{$tmmIdleCycles}; 
         my $total_sleep = $polled_oids->{$tmmSleepCycles}; 
      
         return($total_time,$total_idle,$total_sleep); 
      
     } 
     

  • ah yes, the delta, we did fix this a while back and I believe is included in the current cacti template, though certainly not as elegant as your solution.