org.perf4j.logback
Class JmxAttributeStatisticsAppender

java.lang.Object
  extended by ch.qos.logback.core.spi.ContextAwareBase
      extended by ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.LoggingEvent>
          extended by org.perf4j.logback.JmxAttributeStatisticsAppender
All Implemented Interfaces:
ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent>, ch.qos.logback.core.spi.ContextAware, ch.qos.logback.core.spi.FilterAttachable<ch.qos.logback.classic.spi.LoggingEvent>, ch.qos.logback.core.spi.LifeCycle

public class JmxAttributeStatisticsAppender
extends ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.LoggingEvent>

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, Xu Huisheng

Field Summary
protected  StatisticsExposingMBean mBean
          This is the MBean that is registered with the MBeanServer
 
Fields inherited from class ch.qos.logback.core.AppenderBase
layout, name, started
 
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
 
Constructor Summary
JmxAttributeStatisticsAppender()
           
 
Method Summary
protected  void append(ch.qos.logback.classic.spi.LoggingEvent event)
           
 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.
 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.
 void start()
           
 void stop()
           
 
Methods inherited from class ch.qos.logback.core.AppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getFirstFilter, getLayout, getName, isStarted, setLayout, setName, toString
 
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getStatusManager, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
 

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.

start

public void start()
Specified by:
start in interface ch.qos.logback.core.spi.LifeCycle
Overrides:
start in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.LoggingEvent>

stop

public void stop()
Specified by:
stop in interface ch.qos.logback.core.spi.LifeCycle
Overrides:
stop in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.LoggingEvent>

append

protected void append(ch.qos.logback.classic.spi.LoggingEvent event)
Specified by:
append in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.LoggingEvent>

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.