-0.9.8.1.jar 集成Log4J
Perf4J的扩展功能大部分通过一套定制的log4j appender提供。这样开发人员就能在部署阶段通过非 常熟悉的日志框架来零零散散的添加分析和监控功能(未来的Perf4J将提供定制logback appender和 java.util.logging处理器)。其中一个重要的功能是允许Perf4J作为JMX MBeans的属性展示性能数据, 同时在性能低于可接受的阈值时发送JMX通知。因为JMX已经成为处理和监控Java应用的标准接口,提供 Perf4J MBean开启了广泛的由第三方监控应用提供的功能。举例来说,我们Homeaway的IT部门标准化了 Nagios和Cacti用于系统监控,这两个工具都支持把MBeans作为数据源查询。
下面的log4j.xml文件示例显示了如何启用用于JMX的Perf4J appender:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false" xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Perf4J appenders -->
<!--
This AsyncCoalescingStatisticsAppender groups StopWatch log messages
into GroupedTimingStatistics messages which it sends on the
file appender and perf4jJmxAppender defined below
-->
<appender name="CoalescingStatistics"
class="org.perf4j.log4j.AsyncCoalescingStatisticsAppender">
<!--
The TimeSlice option means timing logs are aggregated every 10 secs.
-->
<param name="TimeSlice" value="10000"/>
<appender-ref ref="fileAppender"/>
<appender-ref ref="perf4jJmxAppender"/>
</appender>
<!--
This file appender is used to output aggregated performance statistics
in a format identical to that produced by the LogParser.
-->
<appender name="fileAppender" class="org.apache.log4j.FileAppender">
<param name="File" value="perfStats.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<!--
This JMX appender creates an MBean and publishes it to the platform MBean
server by
default.
-->
<appender name="perf4jJmxAppender"
class="org.perf4j.log4j.JmxAttributeStatisticsAppender">
< BR> <!-- The tag names whose statistics should be exposed as MBean attributes. -->
<param name="TagNamesToExpose" value="firstBlock,secondBlock"/>
<!--
The NotificationThresholds param configures the sending of JMX notifications
when statistic values exceed specified thresholds. This config states that
the firstBlock max value should be bet
|