VMware Cloud Community
paullizer
Contributor
Contributor

View VM Status Script - How to Increase Performance?

Hello,

I have been researching how to grab VM View Status (connected, available, startup, deleting, etc.). I have a script that leverages several capabilities to collect the proper information for determining the desktop statuses that one sees in View. However, it currently takes 3 seconds per VM. I need to get it under 1 second as I have 1000s of pooled VMs to collect. I've looked at doing this by scraping View but, its not a webpage, its flash page.

It does work and will work if you have 50-100 vms you want to poll every hour or 30 minutes but beyond that it takes too much work.

Essentially you need the following commands all run from the View server so you have access to View PowerCLI, as well as vSphere PowerCLI installed on View server.

vdmadmin.exe

Get-VM

Get-DesktopVM

LDAP Connection to ADAM DB

Gwmi Win32_ComputerSystem -Comp

I run those commands per VM into a variable to leverage the data

    

$poolVMs = get-vm *[name]*

$objGetVM = $poolVMs[$vmNum]

$objVDM = vdmadmin.exe -A -d $poolName -m $vmName -getstatus

$objGetDesktop = get-desktopvm -name $vmName

$LDAPPath = 'LDAP://' + $viewServer + ':389/OU=Servers,DC=vdi,DC=vmware,DC=int'

$LDAPEntry = New-Object DirectoryServices.DirectoryEntry $LDAPPath

# Create a selector and start searching from the path specified in $LDAPPath

$Selector = New-Object DirectoryServices.DirectorySearcher

$Selector.SearchRoot = $LDAPEntry

$Selector.Filter = "(&(objectClass=pae-VM)(iphostnumber=" + $vmName + ".serco.cms))"

$objADAM = $Selector.FindAll()


$objSession = Gwmi Win32_ComputerSystem -Comp $vmName

This is the set of if, elseif, else statements that provide the 'algorithm' to determine the status of the vm

if(    $objVDM[8].Split(" ")[2] -eq 0 -and

    $objGetVM.PowerState -eq "PoweredOn" -and

    $objGetDesktop.hostname -and

    $objGetDesktop.ipaddress -and

    $objGetDesktop.isinpool -eq "true" -and

    $objADAM[0].properties.'pae-vmstate' -eq "READY" -and

    $objSession.username

    ){

    $intConnected++

    #Write-Host $vmName "Is Connected"

}

elseif (    $objADAM[0].properties.'pae-vmstate' -eq "DELETING"   

            ){

    $intDeleting++

    #Write-Host $vmName "Is Deleting"

}

elseif (    !$objVDM -and

            $objGetVM.PowerState -eq "PoweredOff" -and

            !$objGetDesktop.ipaddress -and

            $objGetDesktop.isinpool -eq "false" -and

            !$objADAM[0]   

            ){

    $intProvisioning++

    #Write-Host $vmName "Is Provisioning"

}

elseif (    !$objVDM -and

            $objGetVM.PowerState -eq "PoweredOn" -and

            $objGetDesktop.ipaddress -and

            $objADAM[0].properties.'pae-vmstate' -eq "READY"   

            ){

    $intUnreachable++

    #Write-Host $vmName "Is Agent Unreachable"

}

elseif (    !$objVDM -and

            $objGetVM.PowerState -eq "PoweredOn" -and

            $objGetDesktop.guestfullname -and

            !$objGetDesktop.ipaddress -and

            $objGetDesktop.isinpool -eq "true" -and

            !$objADAM[0]   

            ){

    $intCustomizing++

    #Write-Host $vmName "Is Customizing"

}

elseif (    $objGetDesktop.composerTask -eq "mkChkPoint" -and

            $objADAM[0].properties.'pae-vmstate' -eq "CUSTOMIZING" -and

            $objADAM[0].properties.'pae-svivmoperationstatus' -eq "scheduled"

            ){

    $intCustomizingChkpnt++

    #Write-Host $vmName "Is Customizing - Refreshing Checkpoint"

}

elseif (    !$objVDM -and

            $objGetVM.PowerState -eq "PoweredOn" -and

            !!$objGetDesktop.guestfullname -and

            !$objGetDesktop.ipaddress -and

            $objGetDesktop.isinpool -eq "true" -and

            $objADAM[0]   

            ){

    $intStartup++

    #Write-Host $vmName "Is Startup"

}

elseif (    !$objVDM -and

            $objGetVM.PowerState -eq "PoweredOff" -and

            !$objGetDesktop.ipaddress -and

            $objGetDesktop.isinpool -eq "true" -and

            $objADAM[0]   

            ){

    $intProvisioned++

    #Write-Host $vmName "Is Provisioned"

}

else {

    $intAvailable++

    #Write-Host $vmName "Is Available"

}


I think i can speed up polling by using Get-View with filters instead of Get-VM


The reason I am sharing this is because I thought someone else could help speed up the process, thoughts on speeding it up, or know of another way.

My next steps:

  1. is to implement with Get-View
  2. Split up pool polling so speed up the time to complete but there is a problem due to limit of sessions to VIServer that I need to work with/around.


Does anyone have any support to this work you can provide?

I will attach my code and config files if anyone is interested.


0 Kudos
4 Replies
LucD
Leadership
Leadership

There are some parts that I think you could optimise for speed.

  • The Get-View is one
  • Limit it to 1 LDAP query, and keep the returned data in a hash table
  • Move the more restrictive conditions forward in the If-statement, or split the tests in more If-statements instead of  repeating the same conditions with -and
  • ...

How many pool are you talking about, since you mention that the number of sessions to the vCenter might be a limit ?

I'll have a further go at the code, when I have access to my View lab


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
paullizer
Contributor
Contributor

Containing the LDAP query to a hash table is a good idea. I will also look at the logic and see if I can nest the queries into the if statements to be run only if necessary.

5 sites with 3-6 pools per site ranging from 300-1000 vms per pool

I appreciate your reply LucD

0 Kudos
iefke
Enthusiast
Enthusiast

Using the Quest AD cmdlets (Get-QADObject) to perform LDAP queries to View is very fast.  Please let us know the improvements of the script.

Examples:

vNugglets: VMware View reporting -- PowerShell without Broker-based cmdlets -- Part 0

Blog: http://www.ivobeerens.nl
0 Kudos
JMAlmagro
Contributor
Contributor

Hi!

First, sorry for my poor english, I'll try to explain this as best as I can.

I'm taking parts of this code to write a script to report Agent Unreachable status on View.

I already have a lot of information, but I was not be able to determine which fields may I match to catch the Agent Unreachable status.

So, in this code I can see that, to get an "Agent Unreachable" status, $objVDM variable must be empty, the VM must be powered on and with IP Address, and pae-vmstate must be ready.


The problem is that when you execute the vdmadmin command to determine agent status (vdmadmin -A -d <pool> -m <vmachine> -getstatus) the result is never empty, so I never obtain "Agent Unreachable" status.

Why is this "if" sentence as this?

Thanks!

0 Kudos