Tutorial :I need to develop a webservices monitoring .net Application. What is best way to design this



Question:

Need to develop a Webserver Monitoring system. There may be Hundreds of webserver running on different servers. This system need to keep monitoring of each webservice at a given interva and update the status in DB.

The current options designed.

Options1: Created class Monitorig it has Method1 which call the webservice dynamically on regular interval say 10 Min. And stores the status(Fail/Success) data to DB.

In a for loop I'm creating a new instance of monitoring class every time and a new Thread.

Example.

foreach(int i in idlist)  {  Monitoring monObj = new Monitoring();  Thread workerT = new Thread(monObj.MonitorWebService);  workerT.Start(i);  }  

in the MonitorWebService API there is a infinity for loop which does calling of the given webservice at a given interval as 1 min or 10 min etc. To process this in a regular inverval I'm using EventWaitHandle.WaitOne(T1 * 1000, false) instead of Thread.Sleep(). Here T1 can be 1 min or 1 or 5 hours.

Oprion 2:

in the for loop open a new appdomain with new Name and open a new thread as given below.

foreach(int i in idlist)  {  string appDNname = WSMonitor + i.ToString();  AppDomain WMSObj = AppDomain.CreateDomain(appDNname);  Type t= typeof(Monitoring);  Monitoring monWSObj = (Monitoring) WMSObj.CreateInstanceAndUnwrap(Assembly.GetExecuti ngAssembly().FullName, t.FullName);  Thread WorkerT = new Thread(monWSObj.MonitorWebService);  WorkerT.Start(i);  }  

in option2 I'm unloading the AppDomain when the time interval is more then 10 min. And when ever its required loading. I thought option 2 will release resource when its not required and reload when its required.

Which is the best/better approach? Do we have any better solution. A Quick Help is highly appreciated.


Solution:1

First of all:

Option 2 is bad. It will not unload any more data than your Option 1 does. .Net will automatically unload all application data when it is no longer referenced/needed. It just won't unload the application itself. But in your case you cannot unload your application itself anyways so using an AppDomain is completely useless here.

Option 1 is not terribly good either because (abusing) Threadsyncs for timining has huge overhead and is never a good idea.

Better options are:

1) If you don't need to run permanently just have the external windows task scheduler call your application at the needed times. This has the advantage that it is easily externally configurable and you don't have to worry about any timing in your code at all.

2) If you need/want to run permanently then the most simple and clear way would be to use one of the available Timer objects.

3) If you don't like 2) use a loop with Thread.Sleep (Don't try to abuse the Sleep interval for timing, just sleep e.g. 1 min and then wake up and check if things need to be done).


Solution:2

Did you consider using an existing website monitoring solutions such as Nagios, Pingdom or AlertFox?

I mention this because we once had our own homegrown monitoring system but then gave up and outsourced it.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »