[mrtg] cpuinfo

Andrés andres at redys.com
Wed May 31 12:33:29 MEST 2000


Hello.

I'm trying to use this contrib script on my Linux RedHat 6.0 box, but it
doesn't
work correctly because the first two values doesn't appear, look:

------------------------
[root at localhost mrtg-2.8.12]# ./cpuinfo.pl localhost linux


2 days
localhost
-------------------------

I hacked a bit the code because I connect to localhost, so I don't need
rsh. I have systat 3.2 installed and running. Look at the part I hacked:

--------------------------
sub linux


   # Run commands
   $getcpu = `/usr/bin/sar -u 1 10 | grep Average`;
   $getuptime = `/usr/bin/uptime`;

   # Parse though getcpu and get data
   $getcpu =~
/^Average:\s+(\d+).(\d+)%\s+(\d+).(\d+)%\s+(\d+).(\d+)%\s+(\d+).\d+)%/;
   $getcpuusr = $1;
   $getcpusys = $5;

   # Print getcpu data for mrtg
   print $getcpuusr."\n";
   print $getcpusys."\n";

   # Parse though getuptime and get data
   $getuptime =~ /^\s+(\d{1,2}:\d{2}..)\s+up\s+(\d+)\s+(\w+),/;

   # Print getuptime data for mrtg
   print $2." ".$3."\n";
--------------------------

Look what "sar -u 1 10" shows me:

--------------------------
Linux 2.2.5-15 (localhost.localdomain)  05/31/00

02:17:04          CPU     %user     %nice   %system     %idle
02:17:05          all      0.00      0.00      2.00     98.00
02:17:06          all      0.00      0.00      2.00     98.00
02:17:07          all      0.00      0.00      2.00     98.00
02:17:08          all      0.00      0.00      2.00     98.00
02:17:09          all      0.00      0.00      2.00     98.00
02:17:10          all      0.00      0.00      2.00     98.00
02:17:11          all      2.00      0.00      3.00     95.00
02:17:12          all      1.00      0.00      1.00     98.00
02:17:13          all      1.00      0.00      1.00     98.00
02:17:14          all      0.00      0.00      2.00     98.00
Average:          all      0.40      0.00      1.90     97.70
--------------------------

And "/usr/bin/sar -u 1 10 | grep Average":

--------------------------
Average:          all      0.40      0.00      1.90     97.70
--------------------------


I suppose that the problem is parsing the output of sar, but as I know very
little perl I can't fix it by myself.

Could anyone help me please?

Thanks in advance.



--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org



More information about the mrtg mailing list