Shell – script for logging all the stats for a particular process

centoscpuiomonitoringshell-script

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!

Best Answer

How about PidStat?. Have you tried it? You may need the Pid for the process you want to monitor, but that should be fairly easy to get with the ps command and a bit of awk chop-chopping.

It's part of the package sysstat which you can install in .deb based systems by typing apt-get install sysstat

Related Question