[nylug-talk] Getting CPU utilization programmatically

Frank D. Greco
Sat Sep 2 14:28:01 EDT 2006


At 08:00 AM 9/1/2006, Lawrence Timmins wrote:
>A lot of what you're thinking about is well documented here:
>
> 
>http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/admin-primer/s1-resource-rhlspec.html

         Thanks Lawrence.  I know about these tools.  I was looking for a
         lower-level programmatic interface to this information, particularly
         cpu usage (utilization)... and particularly from Java.  That's
         why the /proc interface is of interest.  I've already written a series
         of C pgms that use well-known interfaces, ie, sysinfo(), but I
         need to either wrap these pgms with JNI (ugh) or find higher-level
         ways via /proc pseudofiles.

>Remember:  You're dealing with 4 variables and kernel time and  user 
>time are like comparing jet fuel and lighter fluid.  So util  = 
>total - idle is a bit misleading if you are concerned about 
>whether  the system is running smoothly.

         Totally agree.

         I'm writing a bunch of system probes that put their
         information into a set of cooperating object databases acting as
         a distributed shared memory pool.  Anyone, anywhere can get access
         to the stats of our network health with a high-degree of reliability,
         even a Blackberry.  Its part of a larger P2P SOA Management project.

>mpstat is like iostat, but with the addition of interrupts per 
>second  being handled by the processor as a 5th column; and that 
>mpstat lets  you see how well each CPU is running on a 2-way or 
>4-way CPU  system.

         Btw, I've discovered that if I use 'mpstat 1 1', it coincides with my
         calculations from reading /proc/stat.

>As far as /proc/stat:
>
>man 5 proc

         Yes, I know... man is your friend (sounds like a line from a 
Tarzan movie). :)
         I did read that manpage.  Good info there of course.

         The optimal thing for me to discover is a Java package that contained
         interfaces to /proc.  I've yet to discover this as I swim in 
the ether.

>   A nice article on /proc/stat appears every so often in linuxgazette, etc.

         Good pointer.  Thanks again.

         Frank G.
          - NYJavaSIG
--
+==============================================+
| Crossroads Technologies Inc.                 |
| www.CrossroadsTech dot com                   |
| fgreco at REMOVEtheX!cross!roads!tech!dotXcom|
+==============================================+
--



More information about the nylug-talk mailing list