Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
    
Are you trying to fetch the values in a script or merely watch the processes? If you are only watching, maybe htop would suffice more for the job. –  Tim Apr 25 '12 at 16:31
    
I'm really only interested in watching the VM processes themselves, those started with the 'vmware-vmx' command. The real kicker is that neither top nor htop will show me the actual names of the vms (or rather, the .vmx argument to the vmware-vmx command used to start the vm) since that will tell me which vms are most active. As it is, I have to write the list of PIDs on a piece of paper and then run top to see who's doing what. Perhaps I should hack top.c to do what I want! :) –  bo gusman Apr 25 '12 at 16:51
    
Curious, is that VMWare Server v 2.0 or something? If you ever move to ESXi all this information will be at your finger tips, and can be automated via Java, C#, Perl, etc. –  Tim Apr 25 '12 at 17:02
    
Worse than that - VMWare Server 1.0.8. We know that we're WAY out of support and are working to get to something more modern (probably CentOS 6 w/ KVM for financial reasons). Lots of barriers in the way, sadly, but we're slowly getting there. –  bo gusman Apr 25 '12 at 17:05
    
Cool, thanks for letting me know. When you guys get around to looking at it, at least see if ESXi free version or XenServer free version is something that fits your needs. –  Tim Apr 25 '12 at 17:08

2 Answers 2

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

share|improve this answer

You can use stty to set the cols to get larger top output.

stty cols 500 && top

Resizing your terminal will reset the cols setting and you'll lose it. You can use something like the script below to do batch output for further processing. It tries to maintain the old cols setting, so you may need to tweak that depending on the system (Tested on RHEL/CentOS/SL6.1)

#!/bin/bash
OLDCOLS=$(stty -a | grep columns | sed 's/.*columns \(.*\); line.*/\1/')
stty cols 500
IFS="
"
PIDS=$(ps axuww | grep "$1" | grep -v grep | awk '{print $2}' | tr '\n' ',' | sed 's/^/-p/;s/,$//')
OUTPUT=$(top -bcn1 $PIDS)
echo "$OUTPUT"
stty cols $OLDCOLS

Script is used like ./scriptname vmware-vmx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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