views:

58

answers:

4

I am building a monitoring application to continuously monitor all aspects of my system. I was hoping to use the Ping() function to determine if the server is up but the MSDN documentation itself says that it is not the best way:

A successful Ping indicates only that the remote host can be reached on the network; the presence of higher level services (such as a Web server) on the remote host is not guaranteed.

Are there any other ways to do this better?

+2  A: 

I usually expose a Ping web method on my server, which sometimes also does some basic healthchecks of the system (if appropriate). Then its just a matter of a web call to your Ping method and you know the state of your system.

Grzenio
+4  A: 

You'll need to settle on one page/url that you wish to test, either one that's already there or one that you create for the specific purpose of checking the servers availability.

Once every [period of time] you can make a request to this url and examine the response to determine if it contain the expected value(s), such as the content of a page if you requested mysite.com/default.aspx. The best thing to do is to dedicate one url/page/web service call to the "ping" as it ensures that it doesn't get broken if the content of the arbitary page you're checking is changed without you being made aware.

One thing I do recommend against doing is having this one ping method test everything, including your database connectivity, 3rd party web service availability, disk space, etc,... If you want to do this, have multiple methods that you can call so you can see at a glance precisely what's causing the problem.

Rob
My usual practice is to create a status page (restricted to internal visiblity only) which dumps out an xml doc detailing the state of sub-components - provides both a single port of call and detailed system info.
annakata
good idea. thanks!
Raze2dust
+1  A: 

Just create a handler (or a page) for your site which returns some information about your system in xml, json or any other format e.g.

database: ok
service x: ok

Then use WebClient to retrieve that information

var client = new WebClient();
string response = client.DownloadString("http://mydomain.com/state.ashx");
// parse information
Mika Kolari
+1  A: 

Or you can do a nice Socket connection to the IIS port (default 80). Send a string like "PING\r\n" and see what you get in return.

You would normally get a "HTTP/1.1 400 Bad Request...." msg in return. That way you know its up and running.

If you can not get a connection the web server is either down or something is blocking inbetween (firewalls / router settings etc).

Wolf5