Forum Discussion
banjoooooooooo_
Nimbostratus
Oct 08, 2008Cpu 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
Sort By
- Kevin_51676
Nimbostratus
I pipe the output of the script into Cacti for graphing purposes. - Kevin_51676
Nimbostratus
Here is what I use for the TMM CPU: - Kevin_51676
Nimbostratus
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 - Zafer_101134
Nimbostratus
Hi - hwidjaja_37598
Altostratus
try this:my ($host, $snmp_comm) = @ARGV;
- zafer
Nimbostratus
it worked - steve_111974
Nimbostratus
hi, i'm running 9.3.1. i copied your script for cpu utilization (f5-bigip-tmm-cpu.pl).
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects