Web Site Monitoring made simple… i.e. no multi-million dollar monitoring systems.

Do you need to monitor a web application, but don’t have an expensive monitoring system available?  Do you have more than one server?  Well, you are in luck.

I have servers in multiple data centers on different subnets that allow me to have one monitor the other.  This is far from foolproof if you lose the network you have lost both, but if the network is down then both are unreachable anyway, monitoring is not important.  Everyone knows that everything is down.

This lightweight monitoring lets you know when your tomcat server or IIS server has stopped.  When your javascript web app has crashed, etc…  or when it failed to start after a reboot




The following code is some PowerShell cobbled together from the web and run on the monitoring server on schedule using Powershell:


Function Mailer ($emailTo)

<# This is a simple function that that sends an email message.


$message = @”

The Server on ServerName is not responsive.

If you see this message repeatedly something is wrong on ServerName with the server.
Log on to the server via remote desktop and check Server.

$emailFrom = “SupportEmail@yourdomain.com”
$subject=”Server on servername is not responsive!!!”
$smtp=new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $message)

# First we create the request.
$HTTP_Request = [System.Net.WebRequest]::Create(‘http://yoursite&#8217;)

# We then get a response from the site.
$HTTP_Response = $HTTP_Request.GetResponse()

# We then get the HTTP code as an integer.
$HTTP_Status = [int]$HTTP_Response.StatusCode

If ($HTTP_Status -eq 200) {
Write-Host “Site is OK!”

Else {
Write-Host “The Site may be down, please check!”
Mailer (‘your.email@yourdomain’ )

# Finally, we clean up the http request by closing it.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s