Blame | Last modification | View Log | RSS feed
Introduction============stat4j is Free Software. stat4j is released under the terms of theApache, version 2.0 license which may be viewed at:http://www.apache.org/licenses/LICENSE-2.0What is stat4j?===============stat4j is a a simple,lightweight extension to log4j that allows you to mine yourlogs in real-time for statistical information. It can be used to:.Measure and profile application performance.Report on business level statistics such as the number of widgets soldor the number of users logged into your site.Alert for events that indicate production problemsstat4j may be used by any Java/J2EE application that uses log4j for logging.stat4j supports Java 1.4 and above.Features include:.A log4J appender for intercepting log messages.A metrics engine for filtering and scraping metrics from log messages.Pre-built calculators to dervive statistics using common statistical functions.Threshold based alerting.An RSS Appender for outputing logs and statistics in RSS formatWhen should you use stat4j?=========================.When you want to use a lightweight mechanism for measuring application performance orcapturing user defined statistics of interest to you or your business.When you have a mature application and you dont want to use byte code instrumention orinvest in exspensive tools.When you have copious log messages and want to leverage these into useful metrics -in real-timeStat4j is free, production friendly and easy to use. It integrates into your application withjust one line of configuration.How does it work? - the 5 second overview=========================================Statistics instrumentation:Statistics may be derived from events or patterns that occur in a log. For example a user countmay be derived by incrementing a count whenever a messge "User() has logged in."occurs and decremented whenever a log message "User() has logged out" occurs. Statistics may be be derived fromsingle (instantaneous) matches or 2 related matches in 2 separate log messages. The unit of measurementmay be time, memory, occurances or a numeric scraped from the message itself. The stat4j appenderintercepts logs and filters them for matches against user pre-defined statistic patterns. If a match isfound then the metric is forwarded into stat4j proper which calculates one or more statistic results.Calculations can be simple counts,rates or more complex functions such as min,max or average. Log messages that dontmatch any patterns are simply discarded i.e no extra I/O.Log filtering and scraping is done using regular expressions.Alerting:In addition to statistics derivation stat4j allows you to define simple threshold based alerts.for example WARN when number of users > 100 or error rate > 10 errors per sec. Alerts are evaluatedwhenever a statistic is calculated and forwarded to a pre-defined log4j alerts category.This can then be logged, sent to JMS, or used to generate an RSS feed.Project Structure=================README.txt Project overviewbuild.xml Ant build file/src stat4j java source/test stat4j junit java source and log configuration/examples stat4j examples including and log configuration/ext external libraries/contributors Comments and src from stat4j contributors/docs Docs generated by build/report unit test report generated by rruning unit testsQuick Start===========To Build:stat4j uses ANT to build. Ensure that you have java 1.4+ and ANT installed on you machine.From the command prompt, cd to the stat4j home directory.Type "ant list" to get a list of targets to buildType "ant compile" to compile stat4j classesType "ant dist" to build the stat4j jar fileType "ant test" to runt the stat4j test casesType "ant doc" to build the stat4j documentationType "ant demo" to run the stat4j demonstraton appTo Use:1) Include the stat4j jar file in the classpath of the application you wish to instrument.e.g java <myApp class> -classpath "libs/log4j.jar;libs/stat4j.jar"2) Configure log4j to use stat4j# Add stat4j Appenderlog4j.appender.stat4j=net.sourceforge.stat4j.log4j.Stat4jAppender# Set stat4j Appender as the default appender for your target log categories,# in this case root. This means all log messages will be sent to# the console and stat4j appenderslog4j.rootCategory=console,stat4j3) Configure the statistics that you want to measurestat4j configuration is managed by the stat4j.properties file. This filecontains the stat4j calculator config and the statistics that you wantcollected.stat4j will load the stat4j.properties automatically from the classpath when stat4j starts up.It is assumed to be at the top of the classpath and so must be present in theclasspath for your application.stat4j.properties contains several pre-defined statistics,filtersand alerts: debug_count,error_count,info_count,debug_rate,error_rate, info_rate and erroralert.To add your own statistics simply follow the examples provided and add your statisticsconfiguration to stat4j.properties.For more information on configuring statistics see the user guide under the docs directory.For examples that use stat4j see the examples directory.For more information on log4j setup and configuration see:http://logging.apache.org/For more information on ANT see:http://ant.apache.org/Roadmap=======1. RSS Appender2. More Calculators3. stat4j aspects - to allow statistics collection via AOP3. Statistics Reporting (push & pull) via RMI/JMX4. XML configuration5. User tagging6. Statistics UI7. Eclipse PluginContacts========stat4j homepage: http://stat4j.sourceforge.net/SourceForge project info: http://sourceforge.net/projects/stat4j/