Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking to log CPU usage to a file over time on an RHEL system, and have seen this, but it doesn't seem to produce the right results - it seems like an anomaly between how ps and top calculate CPU usage.

I am trying to profile an Openfire server's CPU usage as we run various load tests against it. The script I am using does this:

while true;
dateStamp=$(($(date +%s%N)/1000000000))
echo -n $dateStamp >>usage.log
ps -o pcpu,rsz -p $1 | tail -n1 >>usage.log; sleep $2;

But the first data item from ps (pcpu) seems to be cumulative - I would like a simple number for current CPU usage, as is provided by top.

Does anyone know of an approach that provides this?

Thanks in advance


share|improve this question
up vote 2 down vote accepted

I recommend nmon (with nmon analyser). You can get much more than just CPU usage and its extremely easy to use.

share|improve this answer
Looks fantastic, but sadly I won't be allowed to install it on the machine I am doing these tests on :( – Rich Oct 15 '10 at 13:50
This is for a Java app - I ended up using the values exposed through JMX to get the information I wanted (see… for more information). I'm going to accept this answer anyway as it would have done the trick had I had more freedom on the machine! – Rich Oct 18 '10 at 8:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .