[mrtg] Re: CPU Load for Linux Server

Alex van den Bogaerdt alex at slot.hollandcasino.nl
Thu Dec 2 23:22:59 MET 1999


> I need to monitor the CPU load for my Redhat 6.0 Linux server and I
> can't seem to find a good way!! I've tried using the hrProcessorLoad on
> the SNMP but then it doesn't give me accurate readings. Is there any
> other way or other scripts that you know of that can monitor the CPU??
> 

1st of all, make sure you understand the difference between processor
usage and system load.  The output from "uptime" is different from the
processor usage.  If you use the output of uptime, you will probably
be multiplying with 100 (so to get whole numbers) but these do not
represent percentages!

Somewhere on the archive, a long time ago, you should be able to find
a script that I wrote which uses /proc/stat to graph processor usage.
The subject was something with "for linux" in it.

The basics are simple:  grep the "cpu" ("^cpu " for the total, "^cpu1"
for the first cpu etcetera) line from /proc/stat and calculate the
difference from the previous run.

The order on the line is: user, nice, system, idle.  The total of these
four is uptime.  The numbers are in hundreds of seconds.  From the uptime
you can see if your computer booted (in which case the current uptime
number will be lower than the previous one) and if not, you can
determine the exact time inbetween runs.  Determine the ratio from
idle time to uptime (you may want to add nice to idle for this purpose)
and return it to MRTG as a gauge value.

Two runs, taken a few seconds apart, in reverse order:

cpu  723509328 0 148515908 366941905
cpu  723506292 0 148515138 366938901
------------------------------------  -
          3036 0       770      3004

This means: in just over 68 seconds, the processor was idle for about
30 seconds.  This would be (0+3004)/(3036+0+770+3004)*100 = 44 percent.

You could also graph user and system as separate values, or graph
user and user+system (effectively placing the system graph on top of
the user graph).

Regards,
-- 
   __________________________________________________________________
 / alex at slot.hollandcasino.nl                  alex at ergens.op.het.net \
| work                                                         private |
| My employer is capable of speaking therefore I speak only for myself |
+----------------------------------------------------------------------+

--
* To unsubscribe from the mrtg mailing list, send a message with the
  subject: unsubscribe to mrtg-request at list.ee.ethz.ch
* The mailing list archive is at http://www.ee.ethz.ch/~slist/mrtg


More information about the mrtg mailing list