wood burning stoves 2.0*
The moose likes Servlets and the fly likes How to build a rule based Monitoring Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to build a rule based Monitoring Servlet" Watch "How to build a rule based Monitoring Servlet" New topic
Author

How to build a rule based Monitoring Servlet

Pete Neu
Ranch Hand

Joined: Feb 18, 2005
Posts: 86
Hello,

I have this task to build a monitoring servlet which monitors if some production servers are still up and running. One of this production servers
is a tomcat server the other one is an oracle db.

While there are good live monitoring tools for tomcat like lambda probe there is none which checks if the server is still up and running and actively reports errors.

I would need to implement something which just checks if the server is healthy and if not sends out a simple mail to the admins.

I was thinking of just using a servlet and the apache commons http client and testing the http code. If this request is not responded try 3 times more and then send an error message via java mail api.

The monitoring servlet naturally runs on a different tomcat. ;o)

Is that a sane approach or is it altogether stupid doing it like this?

cheers,
Pete
Darren Edwards
Ranch Hand

Joined: Aug 17, 2005
Posts: 69
Your approach seems fine, but I see no reason for you to write it as a servlet as it has no user interaction (aside from perhaps configuration). You could write this as a headless java application and then at a later stage at some servlet configuration pages if they are really needed - you can probably get away with a properties files to start though.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Another thing you should seriously consider is having the application send out alarms through SMS (text messaging to mobile phones) in addition to email, especially if you have a remote administration capability.
That would make the alerts both faster to reach their recipients (I know from personal experience that many people only read their email a few times a day for example) and more secure (having multiple delivery channels makes failed delivery due to a channel being down much less likely).

You will of course have to decide together with your business people whether the extra cost involved in creating and running such a system is worth it.


42
Pete Neu
Ranch Hand

Joined: Feb 18, 2005
Posts: 86
@Darren: You are right. Since the http client does not need a J2EE environement a command line apps will suffice. I will do this then.

@Jeroen: Before doing 2 hours googeling on this subject. Just briefly: How much work is this to setup?
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Never done it, but you need a subscription with some service provider which will then provide you with the APIs and other things needed.
That's the simplest way, you could set up your own equipment to do everything yourself but that's way more expensive unless you plan on sending hundreds or thousands of messages per day.
Darren Edwards
Ranch Hand

Joined: Aug 17, 2005
Posts: 69
Originally posted by Pete Neu:
Before doing 2 hours googeling on this subject. Just briefly: How much work is this to setup?

I don't have the details to hand, but the SMS system we use in work is powered by sending an email. The SMS provider gives us an email to send to, subject is mobile number, body is SMS message and our account is charged 10p per SMS.
Pete Neu
Ranch Hand

Joined: Feb 18, 2005
Posts: 86
I have looked into that option. This is really nice & cheap. I will do that!

There is one last thing I'm thinking about. In order to continually query a certain content from the server for test purposes I will have to implement a thread. This thread runs in an infinite loop as long as it gets a positive response from the server. Between calls it must go into a sleep mode (don't want to generate a home-grown DOS attack). When a response is not answered it must break out of the loop an send an error mail.

That's all? This sounds like a really ugly design. Isn't there a better way in Java to code a behavior like this? I don't like an infinite loop and uncontrolled loop breaks.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Java has a built in mechanism of Timers and TimerTasks which you can use instead.
They're designed for just that kind of work, periodically doing something in the background.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Pete Neu:
I have looked into that option. This is really nice & cheap. I will do that!

There is one last thing I'm thinking about. In order to continually query a certain content from the server for test purposes I will have to implement a thread. This thread runs in an infinite loop as long as it gets a positive response from the server. Between calls it must go into a sleep mode (don't want to generate a home-grown DOS attack). When a response is not answered it must break out of the loop an send an error mail.

That's all? This sounds like a really ugly design. Isn't there a better way in Java to code a behavior like this? I don't like an infinite loop and uncontrolled loop breaks.


See:
http://www.onjava.com/pub/a/onjava/2004/03/10/quartz.html?page=1


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
 
subject: How to build a rule based Monitoring Servlet
 
Similar Threads
Getting server port number in servlet init method
Starting a java process via servlet
How to use Aspirin
Measuring performance of a Application
Any Insight on how JavaRanch scales