SUSE Conversations

Application Monitoring Made Easy for Java Applications – Include / Exclude Filters


May 28, 2008 8:03 am





Apache 2.0

download url:
home page url:

In an earlier article (, I presented a simple a method for generating a maintenance free system level view of the status of your backroom applications without the need to refactor any of your code.

The key requirements for this solution are:

  • Java application
  • Log4j logging
  • Nagios monitoring

If your application is like many, though, you may find that there are specific messages you want to ignore … like an ERROR level message that really should have been a DEBUG level. Or perhaps you’re thinking of using Nagios for the first time, and you have a specific error you’re interested in, and can ignore the rest for the time being … By using the log4j facility, in conjunction with the NagiosAppender, we can easily use the existing include / exclude fitler capability to clearly identify the set of messages we want to monitor.

To use filters, first we need to turn the feature on in the NagiosAppender configuration.


or, if you’re using log4.xml

<param name=”IncludeFilterEnabled” value=”true”/>
<param name=”ExcludeFilterEnabled” value=”true”/>
<param name=”PatternFilterFile” value=”conf/”/>

Notice that you can turn include or exclude filters separately.

Now we can turn our attention to the filters file. This file contains a list of regular expressions we are going to use to drive our filter engine. Here is an example of a configuration that passes on all messages, because we’re including everything, and excluding nothing (… not a very useful application of filtering ….)


Note that there are no exclude filters registered. This is important, because if we have enabled both include and exclude filtering, we need to pass both filter tests to pass on the message.

Here is an example of a configuration that has been dialed down to listen for just a few specific message signatures. Again, we are defining regular expressions here, not the actual message. Also, we are matching the regular expression against the unformatted raw log4j message, not the formatted message you’ve defined in your PatternLayout.

includeFilter=New account was just registered for user:(.*)
includeFilter=Account was just deleted for user:(.*)
includeFilter=Bug fix 2738 just failed(.*)

Quick Review

    Follow instructions for application monitoring (
    Turn on include and/or exclude filtering in your log4j file as necessary
    Create a properties file that is accessible to your application, and specify it in your log4j file
    Add include and exlude regular expressions to your filters property file


Jarlath Lyons
Senior Software Engineer
Tideworks Technology, Inc.

Technical References

Nagios Server version 2.9
NagiosAppender version 1.2.4
Log4j version 1.2.9

0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0 votes, average: 0.00 out of 5)
You need to be a registered member to rate this post.

Categories: Free Tools, Technical Solutions

Disclaimer: As with everything else at SUSE Conversations, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.