| 5827 |
amar.kumar |
1 |
Introduction
|
|
|
2 |
============
|
|
|
3 |
|
|
|
4 |
stat4j is Free Software. stat4j is released under the terms of the
|
|
|
5 |
Apache, version 2.0 license which may be viewed at:
|
|
|
6 |
|
|
|
7 |
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
8 |
|
|
|
9 |
What is stat4j?
|
|
|
10 |
===============
|
|
|
11 |
|
|
|
12 |
stat4j is a a simple,lightweight extension to log4j that allows you to mine your
|
|
|
13 |
logs in real-time for statistical information. It can be used to:
|
|
|
14 |
.Measure and profile application performance
|
|
|
15 |
.Report on business level statistics such as the number of widgets sold
|
|
|
16 |
or the number of users logged into your site
|
|
|
17 |
.Alert for events that indicate production problems
|
|
|
18 |
|
|
|
19 |
stat4j may be used by any Java/J2EE application that uses log4j for logging.
|
|
|
20 |
stat4j supports Java 1.4 and above.
|
|
|
21 |
|
|
|
22 |
Features include:
|
|
|
23 |
.A log4J appender for intercepting log messages
|
|
|
24 |
.A metrics engine for filtering and scraping metrics from log messages
|
|
|
25 |
.Pre-built calculators to dervive statistics using common statistical functions
|
|
|
26 |
.Threshold based alerting
|
|
|
27 |
.An RSS Appender for outputing logs and statistics in RSS format
|
|
|
28 |
|
|
|
29 |
When should you use stat4j?
|
|
|
30 |
=========================
|
|
|
31 |
.When you want to use a lightweight mechanism for measuring application performance or
|
|
|
32 |
capturing user defined statistics of interest to you or your business
|
|
|
33 |
.When you have a mature application and you dont want to use byte code instrumention or
|
|
|
34 |
invest in exspensive tools
|
|
|
35 |
.When you have copious log messages and want to leverage these into useful metrics -
|
|
|
36 |
in real-time
|
|
|
37 |
|
|
|
38 |
Stat4j is free, production friendly and easy to use. It integrates into your application with
|
|
|
39 |
just one line of configuration.
|
|
|
40 |
|
|
|
41 |
How does it work? - the 5 second overview
|
|
|
42 |
=========================================
|
|
|
43 |
|
|
|
44 |
Statistics instrumentation:
|
|
|
45 |
|
|
|
46 |
Statistics may be derived from events or patterns that occur in a log. For example a user count
|
|
|
47 |
may be derived by incrementing a count whenever a messge "User() has logged in."
|
|
|
48 |
occurs and decremented whenever a log message "User() has logged out" occurs. Statistics may be be derived from
|
|
|
49 |
single (instantaneous) matches or 2 related matches in 2 separate log messages. The unit of measurement
|
|
|
50 |
may be time, memory, occurances or a numeric scraped from the message itself. The stat4j appender
|
|
|
51 |
intercepts logs and filters them for matches against user pre-defined statistic patterns. If a match is
|
|
|
52 |
found then the metric is forwarded into stat4j proper which calculates one or more statistic results.
|
|
|
53 |
Calculations can be simple counts,rates or more complex functions such as min,max or average. Log messages that dont
|
|
|
54 |
match any patterns are simply discarded i.e no extra I/O.
|
|
|
55 |
|
|
|
56 |
Log filtering and scraping is done using regular expressions.
|
|
|
57 |
|
|
|
58 |
Alerting:
|
|
|
59 |
|
|
|
60 |
In addition to statistics derivation stat4j allows you to define simple threshold based alerts.
|
|
|
61 |
for example WARN when number of users > 100 or error rate > 10 errors per sec. Alerts are evaluated
|
|
|
62 |
whenever a statistic is calculated and forwarded to a pre-defined log4j alerts category.
|
|
|
63 |
This can then be logged, sent to JMS, or used to generate an RSS feed.
|
|
|
64 |
|
|
|
65 |
Project Structure
|
|
|
66 |
=================
|
|
|
67 |
README.txt Project overview
|
|
|
68 |
build.xml Ant build file
|
|
|
69 |
/src stat4j java source
|
|
|
70 |
/test stat4j junit java source and log configuration
|
|
|
71 |
/examples stat4j examples including and log configuration
|
|
|
72 |
/ext external libraries
|
|
|
73 |
/contributors Comments and src from stat4j contributors
|
|
|
74 |
/docs Docs generated by build
|
|
|
75 |
/report unit test report generated by rruning unit tests
|
|
|
76 |
|
|
|
77 |
Quick Start
|
|
|
78 |
===========
|
|
|
79 |
|
|
|
80 |
To Build:
|
|
|
81 |
|
|
|
82 |
stat4j uses ANT to build. Ensure that you have java 1.4+ and ANT installed on you machine.
|
|
|
83 |
|
|
|
84 |
From the command prompt, cd to the stat4j home directory.
|
|
|
85 |
|
|
|
86 |
Type "ant list" to get a list of targets to build
|
|
|
87 |
Type "ant compile" to compile stat4j classes
|
|
|
88 |
Type "ant dist" to build the stat4j jar file
|
|
|
89 |
Type "ant test" to runt the stat4j test cases
|
|
|
90 |
Type "ant doc" to build the stat4j documentation
|
|
|
91 |
Type "ant demo" to run the stat4j demonstraton app
|
|
|
92 |
|
|
|
93 |
To Use:
|
|
|
94 |
|
|
|
95 |
1) Include the stat4j jar file in the classpath of the application you wish to instrument.
|
|
|
96 |
|
|
|
97 |
e.g java <myApp class> -classpath "libs/log4j.jar;libs/stat4j.jar"
|
|
|
98 |
|
|
|
99 |
2) Configure log4j to use stat4j
|
|
|
100 |
|
|
|
101 |
# Add stat4j Appender
|
|
|
102 |
log4j.appender.stat4j=net.sourceforge.stat4j.log4j.Stat4jAppender
|
|
|
103 |
|
|
|
104 |
# Set stat4j Appender as the default appender for your target log categories,
|
|
|
105 |
# in this case root. This means all log messages will be sent to
|
|
|
106 |
# the console and stat4j appenders
|
|
|
107 |
log4j.rootCategory=console,stat4j
|
|
|
108 |
|
|
|
109 |
3) Configure the statistics that you want to measure
|
|
|
110 |
|
|
|
111 |
stat4j configuration is managed by the stat4j.properties file. This file
|
|
|
112 |
contains the stat4j calculator config and the statistics that you want
|
|
|
113 |
collected.
|
|
|
114 |
|
|
|
115 |
stat4j will load the stat4j.properties automatically from the classpath when stat4j starts up.
|
|
|
116 |
It is assumed to be at the top of the classpath and so must be present in the
|
|
|
117 |
classpath for your application.
|
|
|
118 |
|
|
|
119 |
stat4j.properties contains several pre-defined statistics,filters
|
|
|
120 |
and alerts: debug_count,error_count,info_count,debug_rate,error_rate, info_rate and error
|
|
|
121 |
alert.
|
|
|
122 |
|
|
|
123 |
To add your own statistics simply follow the examples provided and add your statistics
|
|
|
124 |
configuration to stat4j.properties.
|
|
|
125 |
|
|
|
126 |
For more information on configuring statistics see the user guide under the docs directory.
|
|
|
127 |
|
|
|
128 |
For examples that use stat4j see the examples directory.
|
|
|
129 |
|
|
|
130 |
For more information on log4j setup and configuration see:
|
|
|
131 |
|
|
|
132 |
http://logging.apache.org/
|
|
|
133 |
|
|
|
134 |
For more information on ANT see:
|
|
|
135 |
|
|
|
136 |
http://ant.apache.org/
|
|
|
137 |
|
|
|
138 |
Roadmap
|
|
|
139 |
=======
|
|
|
140 |
|
|
|
141 |
1. RSS Appender
|
|
|
142 |
2. More Calculators
|
|
|
143 |
3. stat4j aspects - to allow statistics collection via AOP
|
|
|
144 |
3. Statistics Reporting (push & pull) via RMI/JMX
|
|
|
145 |
4. XML configuration
|
|
|
146 |
5. User tagging
|
|
|
147 |
6. Statistics UI
|
|
|
148 |
7. Eclipse Plugin
|
|
|
149 |
|
|
|
150 |
Contacts
|
|
|
151 |
========
|
|
|
152 |
|
|
|
153 |
stat4j homepage: http://stat4j.sourceforge.net/
|
|
|
154 |
SourceForge project info: http://sourceforge.net/projects/stat4j/
|
|
|
155 |
|