how to monitor select processes on centos 5.x host?

I would like to monitor a select group of processes, vmware vm's, running on my centos 6 host. "top" gives me most of what I want in that I can use -p to specify only those processes and -c to get the full command line as I'm ultimately interested in seeing the actual names of the VMs being monitored. However, the full command line is too long to be displayed on the screen. I thought about writing the output of top to /tmp and doing some parsing there, but apparently top is only writing 80 chars, truncating the name of the VM.

I thought perhaps I could use 'ps' to so something similar, but CPU usage using this approach never changes - how can that be?

Any suggestions as to how I might pull this off?

TIA!


Solution 1:

To be honest, I would use Monit for this. It's available from RPMForge via yum for your particular version of Linux.

Monit is a tool for monitoring processes and daemons. Usually this is done via PID, but you can also match on a process string. Since VMWare Server process strings end in a "vm_name.vmx" specification, you can set Monit to check against that string. The only example of a VMWare Server 1.0.x system I have handy has ONE VM running, but as long as you know the names of the *.vmx files, you can list them independently in the monit config file.

Here's the output of monit procmatch vmx:

[root@abc ~]# monit procmatch vmx
List of processes matching pattern "vmx":
------------------------------------------
        /usr/lib/vmware/bin/vmware-vmx -# product=2;name=VMware Server;version=2.0.1;buildnumber=156745;licensename=VMware GSX Server for Linux;licenseversion=3.0 build-156745; -@ pipe=/tmp/vmhsdaemon-0/vmx226abb1efa53200b;readyEvent=52 /vmware/abc_Web/abc_Web.vmx
------------------------------------------
Total matches: 1

Adding a small VMWare check entry to the monit config file (create and entry for each unique VM you need to monitor)...

check process vmware
        matching "vmware-vmx"

This shows the status of what's being monitored.

[root@abc ~]# monit status

Process 'vmware-vmx'
  status                            running
  monitoring status                 monitored
  pid                               25171
  parent pid                        1
  uptime                            992d 8h 5m 
  children                          0
  memory kilobytes                  1107796
  memory kilobytes total            1107796
  memory percent                    18.1%
  memory percent total              18.1%
  cpu percent                       0.0%
  cpu percent total                 0.0%
  data collected                    Thu Apr 26 04:49:12 2012

Then, there's a web interface to control processes at http://servername:2812

enter image description here

enter image description here