One of the most common requirements in the world of web development and support is the ability to monitor a website health. This is usually done through some kind of “tool” that will ping/try to reach our site or load some specific content from the site to make sure that the server is responding correctly and respond accordingly.

This approach is mostly valid for most sites. However, I wanted to develop a more “Sitecore specific” solution. The goal of this tutorial is to develop a smart health monitor that will constantly check the status of our CD servers and, in this case, take them out of the load-balancer. So, let’s start this journey!

Health Monitor Page

As you have probably suspected, trying to reach some content in our Sitecore site might not give us a complete picture of the state of our server. Sitecore has several dependencies that can dictate the status of our server like:

  • SQL Server connectivity
  • Solr, Lucene, etc
  • MongoDB (for Sitecore 8 and lower)

Checking for all these factors can be a daunting preposition. However, here is where the EXCELLENT health monitor page by
Robin Hermanussen comes into play. This seemingly simple aspx page will provide us the status of several Sitecore dependencies like the ones mentioned above with a, very convenient, SUCCESS or FAILURE message at the top.
We can then use this message for our next step. So, lets create this page under our webroot Sitecore folder.

A “Healthy” monitor page

Note: We can always customize the code of this aspx page to accommodate which checks are going to be made to our server.

PowerShell Script

Next, we’ll create a PowerShell script that will read this page status which will eventually run on a schedule task:

Where $healthMonitorAddress is the URL of our page

As you can see, this simple script reads the content of our health monitor page and will do something depending on the response. So, before we go any further, lets fire up PowerShell IDE and check our server health monitor response. 😉

In part 2, we’ll polish this script and we’ll add the functionality to remove the server from the cluster in case of a FAILURE state. In addition, we’ll create a schedule task to run this script on a given interval. Stay tuned…

Leave a Reply

Your email address will not be published. Required fields are marked *