0
I want to monitor CPU usage, disk read/write usage for a particular process, say ./myprocess
.
To monitor CPU top
command seems to be a nice option and for read and write iotop
seems to be a handy one.
For example to monitor read/write for every second i use the command iotop -tbod1 | grep "myprocess"
.
My difficulty is I just want only three variables to store, namely read/sec, write/sec, cpu usage/sec. Could you help me with a script that combines the outputs the above said three variables from top
and iotop
to be stored into a log file?
Thanks!
For some reason
dstat
gives different CPU usage fromtop
. I'm not sure why. I'm running a basic cpu intensive code (calculate very large fibonacci number) and seeing two different results. – 0x0 – 2012-03-26T18:37:54.020dstat reads the values from the /proc file system. With a small delay being recognized, those values should be correct. What results do you see in top, what in dstat? Where exactely is the difference? – Valentin – 2012-03-26T20:10:47.367
I understood what was going on. Since I've two cpu cores dstat showed the average while top just showed the percentage of all processes together but not necessarily related to the CPU cores.
dstat
is useful but as you said I want a way to monitor cpu and io usage of a particular process. – 0x0 – 2012-03-26T20:31:31.840Hm, if you know the process ID right after the process started, you could read the content of /proc/<PID>/<file name with stats here>. It should contain both the IO and CPU usage. – Valentin – 2012-03-26T20:49:37.280
How can I use that with
dstat
? Can you given an example using a sample PID? – 0x0 – 2012-03-26T21:09:32.430You can't use that with dstat. What I am trying to say is that you could read out those values yourself :-) Simply write a shell script which reads the values of <PID> out of /proc/<pid>/<bla> and displays them. With a little more time invested, you got your tool.. – Valentin – 2012-03-27T17:33:36.053
I understand your comment. By your method i could lose 1 or two seconds after the process has been started and I would like to avoid that. Nevertheless
dstat
is a very useful tool and +1 for pointing it out to me. – 0x0 – 2012-03-27T17:36:56.143