Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to build a rule based Monitoring Servlet

 
Pete Neu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pete Neu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic