I implemented my own (1 second interval) mpstat command in Perl which seems
to not have the aforementioned bug, getting CPU metrics directly from
/proc/stat.  I thought I'd send it over to you in case it helps troubleshoot
the issue.  

Thanks



-----Original Message-----
From: Debian BTS [mailto:debb...@busoni.debian.org] On Behalf Of Debian Bug
Tracking System
Sent: Monday, February 20, 2012 1:03 PM
To: mmastrogiac...@ultralogistics.com
Subject: Bug#660662: Acknowledgement (sysstat: mpstat shows 0% idle
incorrectly)

Thank you for filing a new Bug report with Debian.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

Your message has been sent to the package maintainer(s):
 Robert Luberda <rob...@debian.org>

If you wish to submit further information on this problem, please
send it to 660...@bugs.debian.org.

Please do not send mail to ow...@bugs.debian.org unless you wish
to report a problem with the Bug-tracking system.

-- 
660662: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=660662
Debian Bug Tracking System
Contact ow...@bugs.debian.org with problems
#!/usr/bin/perl
#NAME: Michael Mastrogiacomo
#DATE: 02-20-2012

print "cpu\t%idle\n";

open(STAT, "< /proc/stat") or die;
while(<STAT>)
{
   if (/^cpu(\d+)/)
   {
      $cpu = $1;
      @f = split;
      $idle_before{$cpu} = $f[4];
      $total_before{$cpu} = $f[1] + $f[2] + $f[3] + $f[4] + $f[5] + $f[6] + 
$f[7] + $f[8] +  $f[9];
   }
}
close(STAT) or die;

sleep(1);

open(STAT, "< /proc/stat") or die;
while(<STAT>)
{
   if (/^cpu(\d+)/)
   {
      $cpu = $1;
      @f = split;
      $idle_after{$cpu} = $f[4];
      $total_after{$cpu} = $f[1] + $f[2] + $f[3] + $f[4] + $f[5] + $f[6] + 
$f[7] + $f[8] +  $f[9];
   }
}
close(STAT) or die;

for($i=0; $i <= $cpu; $i++)
{
   $total = $total_after{$i} - $total_before{$i};
   $idle = $idle_after{$i} - $idle_before{$i};

   if ($total == 0) #avoid division by 0 errors
   {
       $percent_busy = 0;
   }
    else
   {
       $percent_busy = ($total - $idle) * 100 / $total;
   }

   # round it down and add 1 for the percent_busy value for printing
   $show_idle = 100 - int($percent_busy);
   print $i . "\t" . $show_idle . "\n";
}

Reply via email to