Linux Average Cpu Usage

CPU usage: /proc/stat, etc?
Under linux, how do I get an approximate percentage of the current CPU usage? I have two cores. /proc/stat gives me the load average over the last few time periods, but i need a way to measure the CPU usage (preferably without ugly system calls like popen’ing ps for example) altogether at any given instant.
Is there a way?
Sorry, I need to do a non-interactive one with a script, for use in Python.
I don’t have sar, and it’s not in my aptitude listing either..
/proc/stat, the first line, which says “cpu” is the combined stats for all CPUs.
You just need to sum the 2nd (user), 3rd (nice) and 4th (system) row, and divide it by all the available time (5th row is the idle time). Pseudo-code example:
tmp = $2 + $3 + $4
usage = $tmp / ($tmp + $5)
Simple, isn’t it?
.
nc_01_01.avi
… [Trackback]…
[...] Read More Infos here: simplicitylinux.com/linux-average-cpu-usage/ [...]…