JBoss 5 Alarm configuration

Please note: this tutorial has been written for JBoss AS 5 and it's therefore obsolete.
If you want to configure alarms and metrics for WildFly application server we recommend checking this tutorial: Monitoring WildFly with Prometheus

An Alarm indicates that an event (generally an error) has happened in the system. In this article we’re going to show how you can activate alarms to keep track of these error conditions.

Looking for error in the console log is usually cumbersome because the log contains quite a lot of information. You might be interested to isolate only a few conditions like a Memory Threshold or a Deployment error.

JBoss keeps track of Alarm in a Table called the Active Alarmtable. By default this table is disable, you have to activate it through the conf/jboss-service.xml file. Enable the following MBean (about at line 121)

  <mbean code="org.jboss.monitor.services.ActiveAlarmTable"
      <attribute name="SubscriptionList">
            <mbean name="jboss.monitor:*">
               <notification type="jboss.alarm"></notification>
               <notification type="JBOSS_MONITOR_NOTIFICATION"></notification>               
            <mbean name="jboss.system:service=Logging,type=JMXNotificationAppender"></mbean>

Now restart jBoss and verify from the Web Console that the Alarm Table appears in the options (In the Monitoring Menu) :

Adding a Memory monitor

One useful alarm notification could be a Memory monitor. If you want to send an alarm when certain memory thresholds are crossed, then uncomment the following MBean in deploy/monitoring-service.xml

 <mbean code="org.jboss.monitor.services.MemoryMonitor"
    <attribute name="FreeMemoryWarningThreshold">95M</attribute>
    <attribute name="FreeMemoryCriticalThreshold">80M</attribute>    

Set up a threshold near to your Server free memory and verify from the Web Console that the alarm has been emitted: 

jboss alert

Capturing Logging events as alarms

You can as well have your Log4j emit logs as JMX events. This can be achieved by uncommenting the JMX appender (in conf/jboss-log4j.xml):

   <appender name="JMX" class="org.jboss.monitor.services.JMXNotificationAppender">
      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
      <param name="Threshold" value="WARN"/>
      <param name="ObjectName" value="jboss.system:service=Logging,type=JMXNotificationAppender"/>
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d %-5p [%c] %m"/>

And remember to add the appender-ref to the Root appender (at the bottom of log4j file)

      <appender-ref ref="CONSOLE"/>
      <appender-ref ref="FILE"/>
      <appender-ref ref="JMX"/>