org.perf4j.log4j
Class GraphingStatisticsAppender

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

public class GraphingStatisticsAppender
extends AppenderSkeleton
implements AppenderAttachable

This appender is designed to be attached to an AsyncCoalescingStatisticsAppender. It takes the incoming GroupedTimingStatistics log messages and uses this data to update a graphical view of the logged statistics. If ANOTHER appender is then attached to this appender then the graph URLs will be written to the appender on a scheduled basis. Alternatively, the graph can be viewed by setting up a GraphingServlet to expose the graph images.

Author:
Alex Devine

Field Summary
protected static Map<String,GraphingStatisticsAppender> APPENDERS_BY_NAME
          This class keeps track of all appenders of this type that have been created.
protected  StatisticsChartGenerator chartGenerator
          The chart genertor, initialized in the activateOptions method, that stores the data for the chart.
protected  AppenderAttachableImpl downstreamAppenders
          Any downstream appenders are contained in this AppenderAttachableImpl
protected  AtomicLong numLoggedStatistics
          Keeps track of the number of logged GroupedTimingStatistics, which is used to determine when a graph should be written to any attached appenders.
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
 
Constructor Summary
GraphingStatisticsAppender()
           
 
Method Summary
 void activateOptions()
           
 void addAppender(Appender appender)
           
protected  void append(LoggingEvent event)
           
 void close()
           
protected  StatisticsChartGenerator createChartGenerator()
          Helper method creates a new StatisticsChartGenerator based on the options set on this appender.
 Enumeration getAllAppenders()
           
static Collection<GraphingStatisticsAppender> getAllGraphingStatisticsAppenders()
          This static method returns an unmodifiable collection of all GraphingStatisticsAppenders that have been created.
 Appender getAppender(String name)
           
static GraphingStatisticsAppender getAppenderByName(String appenderName)
          This static method returns any created GraphingStatisticsAppender by its name.
 StatisticsChartGenerator getChartGenerator()
          Gets the contained StatisticsChartGenerator that is used to generate the graphs.
 int getDataPointsPerGraph()
          The DataPointsPerGraph option is used to specify how much data should be displayed on each graph before it is written to any attached appenders.
 String getGraphType()
          The GraphType option is used to specify the data that should be displayed on the graph.
 String getTagNamesToGraph()
          The TagNamesToGraph option is used to specify which tags should be logged as a data series on the graph.
 boolean isAttached(Appender appender)
           
 void removeAllAppenders()
           
 void removeAppender(Appender appender)
           
 void removeAppender(String name)
           
 boolean requiresLayout()
           
 void setDataPointsPerGraph(int dataPointsPerGraph)
          Sets the value of the DataPointsPerGraph option.
 void setGraphType(String graphType)
          Sets the value of the GraphType option.
 void setTagNamesToGraph(String tagNamesToGraph)
          Sets the value of the TagNamesToGraph 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

APPENDERS_BY_NAME

protected static final Map<String,GraphingStatisticsAppender> APPENDERS_BY_NAME
This class keeps track of all appenders of this type that have been created. This allows static access to the appenders from the org.perf4j.log4j.servlet.GraphingServlet class.


chartGenerator

protected StatisticsChartGenerator chartGenerator
The chart genertor, initialized in the activateOptions method, that stores the data for the chart.


numLoggedStatistics

protected AtomicLong numLoggedStatistics
Keeps track of the number of logged GroupedTimingStatistics, which is used to determine when a graph should be written to any attached appenders.


downstreamAppenders

protected final AppenderAttachableImpl downstreamAppenders
Any downstream appenders are contained in this AppenderAttachableImpl

Constructor Detail

GraphingStatisticsAppender

public GraphingStatisticsAppender()
Method Detail

getGraphType

public String getGraphType()
The GraphType option is used to specify the data that should be displayed on the graph. Acceptable values are Mean, Min, Max, Count, StdDev and TPS (for transactions per second). Defaults to Mean if not explicitly set.

Returns:
The value of the GraphType option

setGraphType

public void setGraphType(String graphType)
Sets the value of the GraphType option. This must be a valid type, one of Mean, Min, Max, Count, StdDev or TPS (for transactions per second).

Parameters:
graphType - The new value for the GraphType option.

getTagNamesToGraph

public String getTagNamesToGraph()
The TagNamesToGraph option is used to specify which tags should be logged as a data series on the graph. If not specified ALL tags will be drawn on the graph, one series for each tag.

Returns:
The value of the TagNamesToGraph option

setTagNamesToGraph

public void setTagNamesToGraph(String tagNamesToGraph)
Sets the value of the TagNamesToGraph option.

Parameters:
tagNamesToGraph - The new value for the TagNamesToGraph option.

getDataPointsPerGraph

public int getDataPointsPerGraph()
The DataPointsPerGraph option is used to specify how much data should be displayed on each graph before it is written to any attached appenders. Defaults to StatisticsChartGenerator.DEFAULT_MAX_DATA_POINTS.

Returns:
The value of the DataPointsPerGraph option

setDataPointsPerGraph

public void setDataPointsPerGraph(int dataPointsPerGraph)
Sets the value of the DataPointsPerGraph option.

Parameters:
dataPointsPerGraph - The new value for the DataPointsPerGraph option.

activateOptions

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

createChartGenerator

protected StatisticsChartGenerator createChartGenerator()
Helper method creates a new StatisticsChartGenerator based on the options set on this appender. By default a GoogleChartGenerator is created, though subclasses may override this method to create a different type of chart generator.

Returns:
A newly created StatisticsChartGenerator.

getChartGenerator

public StatisticsChartGenerator getChartGenerator()
Gets the contained StatisticsChartGenerator that is used to generate the graphs.

Returns:
The StatisticsChartGenerator used by this appender.

getAppenderByName

public static GraphingStatisticsAppender getAppenderByName(String appenderName)
This static method returns any created GraphingStatisticsAppender by its name.

Parameters:
appenderName - the name of the GraphingStatisticsAppender to return
Returns:
the specified GraphingStatisticsAppender, or null if not found

getAllGraphingStatisticsAppenders

public static Collection<GraphingStatisticsAppender> getAllGraphingStatisticsAppenders()
This static method returns an unmodifiable collection of all GraphingStatisticsAppenders that have been created.

Returns:
The collection of GraphingStatisticsAppenders created in this VM.

addAppender

public void addAppender(Appender appender)
Specified by:
addAppender in interface AppenderAttachable

getAllAppenders

public Enumeration getAllAppenders()
Specified by:
getAllAppenders in interface AppenderAttachable

getAppender

public Appender getAppender(String name)
Specified by:
getAppender in interface AppenderAttachable

isAttached

public boolean isAttached(Appender appender)
Specified by:
isAttached in interface AppenderAttachable

removeAllAppenders

public void removeAllAppenders()
Specified by:
removeAllAppenders in interface AppenderAttachable

removeAppender

public void removeAppender(Appender appender)
Specified by:
removeAppender in interface AppenderAttachable

removeAppender

public void removeAppender(String name)
Specified by:
removeAppender in interface AppenderAttachable

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


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