Featured Post

Cloud Options For Accelerating Workspace One Adoption In Traditional Horizon Environments

Cloud options for VMware Identity Manager and Workspace One UEM (AirWatch) make it easy to quickly extend the benefits of Workspace One to o...

Wednesday, November 22, 2017

RDSH Load Balancing In Horizon Apps Using PowerCLI And vROPs

This post will demonstrate a very meaningful integration between Horizon Apps and vRealize Operations using PowerCLI.  Using Horizon App's customizable load balancing process,  its possible to leverage the metrics and analytics of vROPs to intelligently guide the placement of new RDSH sessions within a Horizon Apps farm.   Load balancing priority of any given RDSH VM can take into consideration the entire vSphere stack supporting that VM, the servers, the storage the networking, etc.. and is not limited to one or two key metrics.  With real time data pulled from vROPs determining the placement of new sessions in a farm, we gain the benefit of an automated response to impacted infrastructure. Not only can we divert sessions away from suspect hardware, but we can also actively guide and shape workloads across our infrastructure based on the in depth visibility vROPs provides.  This potential will be demonstrated with a slightly modified vbscript and powershell script.

The Gist Of The Solution


The proposed solution starts with making slight modifications to the sample load balancing script, cpuutilization.vbs, provided by VMware.  Normally this script determines the load balancing priority of a given RDS host based on cpu utilization.   Sticking with the basic structure of this script we can further refine the process for determining load balancing priority to include vROPs information about the underlying infrastructure.  For this demo in particular, the Health, Workload and Capacity_Remaining badges, or super metrics, of the underlying ESXi hosts will be utilized.

To keep requirements simple on the RDSH VMs themselves, information from vROPs will be relayed to the modified cpuutillization.vbs script via the existence of text files in a remote share.  These text files will be put into place when a PowerCLI script running from an administrative system determines that at vSphere hosts associated with a particular RDSH VM has potential health or capacity issues.  The cpuutilizlation.vbs will in turn lower the load balancing priority of RDSH VM based on the detection of the text file.

The modified cpuutillization.vbs script can be found here at the bottom of this post.  The PowerCLI script that detects problems with underlying ESXi hosts and creates text files accordingly can be found at the bottom of this post as well.  To use these in your own environment replace the server names, user names and passwords with those from your own environment and give it a go.  If you want a more in depth explanation on how the process works, just continue reading.

Creating Your Own Load Balancing Script 


Official guidance for load balancing using customized scripts can be found here: Configuring Load Balancing For RDS Hosts  Sample scripts can be located within the view agent directory on the RDS hosts here: c:\Program Files\VMware\VMware View\Agent\scripts. The basic idea behind these sample scripts, or any custom script you make, is that they produce an exit code from 0 - 3 after running directly on the RDS hosts.   These scripts run on a regular basis - every 5 minutes by default - and their exit codes map out to higher or lower load preferences for Horizon Connections severs to use when deciding where to place new sessions.   An exit code of 3 means an RDS host should be given higher preference priority for taking on new sesssions.  An exit code of 0 means an RDS host should not be given any new sessions at all.   Here's a breakdown of the different exit codes and associated load preferences:




With the sample scripts cpuutilization.vbs and memoryutilization.vbs, higher or lower priority is provided to a RDS host based on cpu or memory usage.  For example, with the cpuutilization.vbs script, hosts with CPU utilization of 90% or higher are given a load preference of block, with an exit code of 0, while host with low CPU utilization under 25% are given high preference with an exit code of 3.




For this demo, the cpuutilization.vbs has been modified to adjust load preference according to both CPU utilization and any health or capacity warnings obtained from vROPs.  Essentially, when there's issues reported by vROPs we're taking the normal exit codes of this script and decrementing by 1.  So if the script would normally spit out an exit code of 3 based on CPU utilization, but currently has issues according to vROPs, the exit code is going to be decremented to 2.  Or if a system already had low preference with an exit code of 1 because of high CPU usage, it will drop down to a load preference of block with an exit code of 0 if issues are detected through vROPs.

The PowerCLI Script 


The PowerCLI script works through a combination of vSphere PowerCLI, Horizon PowerCLI and the PowerCLI module for vROPs.   Initially, Horizon PowerCLI is used determine the RDS hosts that are members of the specified RDSH farm. (This is a process I detailed in a previous blog posts that can be viewed here)   For each RDSH VM in the farm vSphere PowerCLI is used to obtain the name of the vSphere host the VM is running on.  Finally, the PowerCLI module for vROPs is leveraged to obtain super metrics about the ESXi host.

To initially connect to the vROPs manager, we do this:


Connect-OMServer YOUR_VROPS_SERVER -user admin -Password YOUR_PASSWORD

Then, with the name of the ESXi host in hand we can use the Get-OMResource cmdlet to obtain relevent info about the ESXi box.   Here's an example of how to do that.


$EsxiHealth = Get-OMResource VSPHERE_HOST

The object returned by Get-OMResource is chock-full of vROPs information regarding the ESXi host.  Here's an example of retrieving badge information about the vSphere host using the returned object stored in $EsxiHealth.




For our demo load balancing script we're going to zero in on the Health, Capacity_Remaining and Workload badge.   If Health isn't green or Capacity_Remaining or Workload are red a text file is created in the remote share indicating the RDSH VM is sitting on a ESXi box that's suspect.



The RDSH VM in question, InstaApp1, is barely using any CPU and would normally report an exit code of 3 and high load preference.   However, the modified script detects the existence of this text file and accordingly returns an exit code of 2 and load preference of medium.   In Horizon Administrator, we can see that as a result the load balance status goes from this:



To this:



The modified cpuutilization.vbs script:



The PowerShell script: