Tuesday, December 25, 2012

Citrix XenDesktop Health Monitoring - Desktop Availability

Monitoring is a crucial task in a critical environment. Proper monitoring can help mitigate critical situations proactively while minimizing the damage. As a Systems Engineer I always prefer the concept of being notified when something out of the ordinary happens in the systems that I am responsible of keeping alive. In other words I love knowing what is coming towards me than saying "Oh, that's what hit me!" after I get hit.

A XenDesktop environment isn't always critical but when it grows with more desktops, more infrastructure servers and especially when it has many customers depending on its proper functionality to fulfill their tasks the availability of the desktops is crucial. Unless you are working only with Citrix XenDesktop in a daily manner but work with many other different infrastructures simultaneously you would hardly find time to navigate to the console and check how the desktops are performing every day. "Hey Nimantha, I've been trying to log in to this Citrix Desktop for some time but it takes ages and still does not log me in!", then it comes to my mind "damn, what is going on there... I didn't log into it in.. like.. months...!". Then only we get the idea of opening the console and see what is out of the ordinary but now the problem has already occurred. What if I got a report of the health of the XenDesktop environment early in the morning stating that there are a number of them doing not-so-well. Well, then as soon as the guy says, "Hey Nimantha, I've been trying to log in to this Citrix Desktop for..." I would know "Aha, this must be the issue..." or I may already have solved that issue as soon as I saw the report in the morning and the customer never had to experience it.Long story short, what I did is I created a powershell script that would examine the status of the desktops and the critical infrastructure (the Delivery Controllers, the Provisioning Servers, the XenServers, etc.) at a given schedule and send a report including the statistics in an email to me and my team. For me this report saves a lot of time that I had to spend logging on to the Delivery Controller, then opening the Desktop Studio, then navigating to each desktop group and check the status of the desktops. To be honest although I had the idea of creating this script I had no idea where to start and neither did I know powershell. But, one day, thanks to Miguel Contreras who posted a skeleton script for this purpose in one of his blog posts I was determined to do this somehow and that led me to creating this script and also to mastering powershell along the way.

This script does 6 things.1. Look for pooled VMs that have not rebooted since the last user logged off and resets them if there are any.2. Look for VMs that are powered on and unregistered.3. Look for VMs that are in maintenance mode.4. Check the availability of the infrastructure servers using ping.5. Send the summary of 2, 3, and 4 as a report to specified recipients in an email.6. Log the summarized report to a specified location.

##----- End of the script -----The resulting email will look like this:

You'll find a LOT (I mean it! :-D) of HTML formatting in this code. What can I say, I am an engineer who has an artistic mind. :-)... and who likes to look at a boring black and white report anyway. ;-)If you feel like doing some tweaking or adding some modifications you'll find Getting Started with PowerShell in XenDesktop 5 useful.I would like to thank the customers for their feedback on the current system, the good and the bad. If not for them I might not have created this script in the first place.

P.S. If you need to copy the script please use CTRL+C. Right click is disabled. :-)You can also download the script here.