org.perf4j.log4j
Class JmxAttributeStatisticsAppender

java.lang.Object
  extended by org.apache.log4j.AppenderSkeleton
      extended by org.perf4j.log4j.JmxAttributeStatisticsAppender
All Implemented Interfaces:
Appender, OptionHandler

public class JmxAttributeStatisticsAppender
extends AppenderSkeleton

This appender is designed to be attached to an AsyncCoalescingStatisticsAppender. It takes the incoming GroupedTimingStatistics log messages and uses this data to update the value of a JMX MBean. The attributes on this MBean can then be monitored by external tools. In addition, this class allows you to specify notification thresholds so that a JMX notification is sent if one of the attributes falls outside an acceptable range (for example, if the mean time for a specific value is too high).

Author:
Alex Devine

Field Summary
protected  StatisticsExposingMBean mBean
          This is the MBean that is registered with the MBeanServer
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
 
Constructor Summary
JmxAttributeStatisticsAppender()
           
 
Method Summary
 void activateOptions()
           
protected  void append(LoggingEvent event)
           
 void close()
           
 String getMBeanName()
          The MBeanName option is used to specify the ObjectName under which the StatisticsExposingMBean in the MBeanServer.
protected  MBeanServer getMBeanServer()
          Gets the MBeanServer that should be used to register the StatisticsExposingMBean.
 String getNotificationThresholds()
          The NotificationThresholds option is a comma-separated list of acceptable range configurations.
 String getTagNamesToExpose()
          The TagNamesToExpose option is a comma-separated list of the tag names whose statistics values (e.g.
 boolean requiresLayout()
           
 void setMBeanName(String mBeanName)
          Sets the value of the MBeanName option.
 void setNotificationThresholds(String notificationThresholds)
          Sets the value of the NotificationThresholds option.
 void setTagNamesToExpose(String tagNamesToExpose)
          Sets the value of the TagNamesToExpose option.
 
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mBean

protected StatisticsExposingMBean mBean
This is the MBean that is registered with the MBeanServer

Constructor Detail

JmxAttributeStatisticsAppender

public JmxAttributeStatisticsAppender()
Method Detail

getMBeanName

public String getMBeanName()
The MBeanName option is used to specify the ObjectName under which the StatisticsExposingMBean in the MBeanServer. If not specified, defaults to org.perf4j:type=StatisticsExposingMBean,name=Perf4J.

Returns:
The value of the MBeanName option

setMBeanName

public void setMBeanName(String mBeanName)
Sets the value of the MBeanName option. This must be a valid JMX ObjectName.

Parameters:
mBeanName - The new value for the MBeanName option.

getTagNamesToExpose

public String getTagNamesToExpose()
The TagNamesToExpose option is a comma-separated list of the tag names whose statistics values (e.g. mean, min, max, etc.) should be exposed as MBeanAttributes. See the StatisticsExposingMBean for more details.

Returns:
The value of the TagNamesToExpose expose

setTagNamesToExpose

public void setTagNamesToExpose(String tagNamesToExpose)
Sets the value of the TagNamesToExpose option.

Parameters:
tagNamesToExpose - The new value for the TagNamesToExpose option.

getNotificationThresholds

public String getNotificationThresholds()
The NotificationThresholds option is a comma-separated list of acceptable range configurations. An acceptable range configuration specifies the values for which a particular timing statistic is considered good. If the statistic falls outside of this range, then a JMX notification will be sent.

The format of an acceptable range configuration is tagNameStatName(range) where range can be one of <value, >value, or minValue-maxValue. For example, suppose the TagNamesToExpose option was set to "databaseCall,fileWrite". This would cause the generated MBean to expose the following attributes:

Suppose you wanted to have a JMX notification sent if the databaseCallMean is ever greater than 100ms, the databaseCallMax is ever greater than 1000ms, the fileWriteMean is ever less than 5ms or greater than 200ms, and the fileWriteTPS is ever less than 1 transaction per second. You would specify a NotificationThreshold as:
databaseCallMean(<100),databaseCallMax(<1000),fileWriteMean(5-200),fileWriteTPS(>1)

Returns:
The value of the NotificationThresholds option

setNotificationThresholds

public void setNotificationThresholds(String notificationThresholds)
Sets the value of the NotificationThresholds option.

Parameters:
notificationThresholds - The new value for the NotificationThresholds option.

activateOptions

public void activateOptions()
Specified by:
activateOptions in interface OptionHandler
Overrides:
activateOptions in class AppenderSkeleton

append

protected void append(LoggingEvent event)
Specified by:
append in class AppenderSkeleton

requiresLayout

public boolean requiresLayout()
Specified by:
requiresLayout in interface Appender
Specified by:
requiresLayout in class AppenderSkeleton

close

public void close()
Specified by:
close in interface Appender
Specified by:
close in class AppenderSkeleton

getMBeanServer

protected MBeanServer getMBeanServer()
Gets the MBeanServer that should be used to register the StatisticsExposingMBean. Defaults to the Java Platform MBeanServer. Subclasses could override this to use a different server.

Returns:
The MBeanServer to use for registrations.


Copyright © 2008-2011 perf4j.org. All Rights Reserved.