1

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; do dateStamp=$(($(date +%s%N)/1000000000)) echo -n $dateStamp >>usage.log ps -o pcpu,rsz -p $1 | tail -n1 >>usage.log; sleep $2; done 

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

Rich

1 Answer 1

2

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

2
  • Looks fantastic, but sadly I won't be allowed to install it on the machine I am doing these tests on :( Commented Oct 15, 2010 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 stackoverflow.com/questions/25552/… 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! Commented Oct 18, 2010 at 8:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.