Process monitoring on Unix/Linux/Solaris/HP-UX/AIX

It’s often a requirement to monitor Unix processes in the field of performance monitoring. However, there is a catch. Different flavors of Unix have different process monitoring tools such as `top`. Of course `top` is not available on all platforms. Similarly HP-UX has something called ‘glance’. This is again very platform specific.

The only CLI that is supported for process monitoring across different flavors of Unix is ‘ps’. However, one of the most two parameters that we are interested in process monitoring is its SIZE and CPU usages. Both of these parameters can be retrieved using ‘ps’ CLI.

To obtain size of a process, we generally use PS parameters ‘vsz’. It’s the size of process in virtual memory. To obtain CPU usages of a process, we generally use PS parameter `cpu` which gives absolute CPU usage of a process. On some Unices, PS provides parameter called ‘pcpu’ which provides percentage of CPU usage by a process. There are still limitations of this approach as described above. Few of the unices do not provide ‘pcpu’ parameter and instead provide ‘cpu’ parameter e.g HP-UX.

However, it’s still better to rely on single UNIX provided `ps` CLI that can be used inside a any shell or Perl script. In order to use `ps` CLI we should be relying on UNIX95 Unix standard as defined in the Single UNIX Specification.

e.g. Following CLI prints “our_process” usages on HP-UX with columns viz. process name, its virtual memory size and its absolute CPU usages on single line. It is just a matter of changing cpu to pcpu and application of few filters on some of the Unix platforms as per our requirements. But it does work.

# export UNIX95=1; ps –eo args,vsz,cpu | grep “our_process”

It just a matter of directing output of above CLI to a file post application of filters

# cntr=1;while test $cntr;do export UNIX95=1; ps -eo args,vsz,sz,cpu |egrep -v "our_process" | awk '{print $1"\t"$2\”\t”$4}' ;done >> /tmp/our_process.txt &

Above while loop keep on dumping process virtual memory size and CPU usages of our_process in /tmp/our_process.txt file. Since output is in tabbed format, this output file can be easily opened in Microsoft Excel and graphs can be plotted.

Do you use any other methodology to monitor processes on Unix machines? If yes then do let everyone know in comments below.

Note: We at TechSutram take our ethics very seriously. More information about it can be found here.
Mandar Pise Opinions expressed by techsutram contributors are their own. More details

Mandar is a seasoned software professional for more than a decade. He is Cloud, AI, IoT, Blockchain and Fintech enthusiast. He writes to benefit others from his experiences. His overall goal is to help people learn about the Cloud, AI, IoT, Blockchain and Fintech and the effects they will have economically and socially in the future.

No comments:

Post a Comment

    Your valuable comments are welcome. (Moderated)