Xmpp/Jabber commons-logging handler (Tomcat)

I wanted to create a live monitoring system to use with some of the webapps I have running in Apache Tomcat. There were various options, but as I have a secure xmpp/jabber chat system setup already, I thought it’d be handy to use that as the transport medium for any communication.

On one server I have an xmpp chat system (ejabberd running on debian) running over SSL. On other servers I have instances of Apache Tomcat running various web applications.

  • I created a new java.util.logging.Handler that could be used with tomcat.
  • Created xmpp user accounts within ejabberd for each webapp I wanted to monitor.
  • Updated the logging.properties file for each webapp and restarted.

The handler was setup to auto-accept contact requests (not a problem on an internal chat server), so I added the new xmpp user accounts as contacts on my own account. Step 1 successful, I can now see when the webapps are online and do something about it when I notice they go offline. To receive live logging information, I’d also built the following commands into the handler.

  • !subscribe
  • !unsubscribe
  • !level <LEVEL_NAME>

First two are pretty obvious, they allow you to subscribe and unsubscribe from being sent log messages via chat. The third command allows you to select the minimum level messages you want to see – on production servers I get way too many messages if I listen to ALL, so I tend to choose WARNING as I’m only interested in seeing if things go wrong.

An example logging.properties file updated from the default one that ships with tomcat;

handlers = org.apache.juli.FileHandler, uk.org.tilion.logging.XmppHandler, java.util.logging.ConsoleHandler

uk.org.tilion.logging.XmppHandler.server = chat.tilion.org.uk
uk.org.tilion.logging.XmppHandler.port = 5222
uk.org.tilion.logging.XmppHandler.username = webapp1-name
uk.org.tilion.logging.XmppHandler.password = webapp1-password

org.apache.juli.FileHandler.level = ALL
org.apache.juli.FileHandler.directory = ${catalina.base}/logs

java.util.logging.ConsoleHandler.level = SEVERE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

The code is squeezed into a single file and packaged in a maven project that uses smack/smackx to perform the xmpp communication. I’ve not attached it to this post, but if anyone is interested, leave a comment below and I’ll make it available.

Leave a Reply

Your email address will not be published. Required fields are marked *

Security Question * Time limit is exhausted. Please reload the CAPTCHA.