I'm looking for an application or line of code that would let me observe a process, save the info in a number of variables, then put the gathered info on a file.

I've been trying with variations of top but no luck. I am running several CentOS virtual servers, VM is a 2GB RAM, 2 processor.

A script that works over a specified amount of time while writing lines with the info on a text file so at the end I can have a sort of table with the data would work.

I'm going to stress test the server, and I would like to have the data to make some statistics.

link|improve this question
feedback

2 Answers

up vote 0 down vote accepted

The standard ps is enough.

while true; do ps o pcpu,rsz -p $pid | tail -n1 >>usage.log; sleep $interval; done

result:

0.0  3352
0.3 31640
0.4 36924
0.5 36052
...

First field is CPU usage in %, second is physical memory usage in kbytes.

link|improve this answer
thatas perfect, i had already made a long script to clean all the data from a top batch output, but the is way simple better and efficint i aprreciate t a lot, thanks! – joel_gil Jun 9 '10 at 14:55
at the end i kept using my script, since ps gives me the load average which is normally same as CPU% but is not a rule, more info of this in a quick google search – joel_gil Jun 15 '10 at 15:16
feedback

I would suggest sadc / sar.

link|improve this answer
Isn't it system-wide only? – whitequark Jun 8 '10 at 1:05
@whitequark: It depends on the version of sar. Some versions use sar -x PID others use pidstat -p PID. – Dennis Williamson Jun 8 '10 at 1:36
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.