public class SimonServletFilter extends Object implements javax.servlet.Filter
INIT_PARAM_SIMON_CONSOLE_PATH
is used in web.xml
shouldBeReported(javax.servlet.http.HttpServletRequest, long, java.util.List<org.javasimon.Split>)
- compares actual request nano time with getThreshold(javax.servlet.http.HttpServletRequest)
(which may become unused if this method is overridden)getThreshold(javax.servlet.http.HttpServletRequest)
- returns threshold configured in web.xml
RequestReporter
can be implemented and specified using init parameter INIT_PARAM_REQUEST_REPORTER_CLASS
HttpStopwatchSource
can be subclassed and specified using init parameter INIT_PARAM_STOPWATCH_SOURCE_CLASS
, specifically
following methods are intended for override:
HttpStopwatchSource.isMonitored(javax.servlet.http.HttpServletRequest)
- true except for request with typical resource suffixes
(.gif
, .jpg
, .css
, etc.)HttpStopwatchSource.getMonitorName(javax.servlet.http.HttpServletRequest)
Modifier and Type | Field and Description |
---|---|
protected String |
consolePath
URL path that displays Simon web console (or null if no console is required).
|
static String |
INIT_PARAM_PREFIX
Name of filter init parameter for Simon name prefix.
|
static String |
INIT_PARAM_REPORT_THRESHOLD_MS
Name of filter init parameter that sets the value of threshold in milliseconds for maximal
request duration beyond which all splits will be dumped to log.
|
static String |
INIT_PARAM_REQUEST_REPORTER_CLASS
FQN of the
RequestReporter implementation that is used to report requests
that shouldBeReported(javax.servlet.http.HttpServletRequest, long, java.util.List) . |
static String |
INIT_PARAM_SIMON_CONSOLE_PATH
Name of filter init parameter that sets relative ULR path that will provide Simon console page.
|
static String |
INIT_PARAM_STOPWATCH_SOURCE_CACHE
Enable/disable caching on Stopwatch resolution.
|
static String |
INIT_PARAM_STOPWATCH_SOURCE_CLASS
FQN of the Stopwatch source class implementing
MonitorSource . |
static String |
INIT_PARAM_STOPWATCH_SOURCE_PROPS
Properties for a StopwatchSource class.
|
protected String |
printTreePath
URL path that displays Simon tree - it is console-path without the ending slash.
|
protected Long |
reportThresholdNanos
Threshold in ns - any request longer than this will be reported by current
requestReporter instance. |
Constructor and Description |
---|
SimonServletFilter() |
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Removes the splitSaverCallback if initialized.
|
void |
doFilter(javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse,
javax.servlet.FilterChain filterChain)
Wraps the HTTP request with Simon measuring.
|
Manager |
getManager() |
protected long |
getThreshold(javax.servlet.http.HttpServletRequest request)
Returns actual threshold in *nanoseconds* (not ms as configured) which allows to further customize threshold per request - intended for override.
|
void |
init(javax.servlet.FilterConfig filterConfig)
Initialization method that processes various init parameters from
web.xml and sets manager, if
SimonUtils.MANAGER_SERVLET_CTX_ATTRIBUTE servlet context attribute is not null . |
protected boolean |
shouldBeReported(javax.servlet.http.HttpServletRequest request,
long requestNanoTime,
List<Split> splits)
Determines whether the request is over the threshold - with all incoming parameters this method can be
very flexible.
|
public static final String INIT_PARAM_PREFIX
public static final String INIT_PARAM_REPORT_THRESHOLD_MS
getThreshold(javax.servlet.http.HttpServletRequest)
method,
but this parameter has to be set to non-null value to enable threshold reporting feature (0 for instance).public static final String INIT_PARAM_SIMON_CONSOLE_PATH
public static final String INIT_PARAM_STOPWATCH_SOURCE_CLASS
MonitorSource
.
One can use DisabledMonitorSource
to disabled monitoring.
Defaults to HttpStopwatchSource
.public static final String INIT_PARAM_STOPWATCH_SOURCE_CACHE
HttpServletRequest.getRequestURI()
,
this is incompatible with application passing data in their
request URI, this is often the case of RESTful services.
For instance "/car/1023/driver" and "/car/3624/driver"
may point to the same page but with different URLs.
Defaults to false
.public static final String INIT_PARAM_REQUEST_REPORTER_CLASS
RequestReporter
implementation that is used to report requests
that shouldBeReported(javax.servlet.http.HttpServletRequest, long, java.util.List)
.
Default is DefaultRequestReporter
.public static final String INIT_PARAM_STOPWATCH_SOURCE_PROPS
INIT_PARAM_STOPWATCH_SOURCE_CLASS
protected Long reportThresholdNanos
requestReporter
instance.
Specified by INIT_PARAM_REPORT_THRESHOLD_MS
("report-threshold-ms") in the web.xml
(in ms,
converted to ns during servlet init). This is the default value returned by getThreshold(javax.servlet.http.HttpServletRequest)
but it may be completely ignored if method is overridden so. However if the field is null
threshold reporting feature
is disabled.protected String printTreePath
protected String consolePath
public SimonServletFilter()
public final void init(javax.servlet.FilterConfig filterConfig)
web.xml
and sets manager, if
SimonUtils.MANAGER_SERVLET_CTX_ATTRIBUTE
servlet context attribute is not null
.init
in interface javax.servlet.Filter
filterConfig
- filter config objectpublic final void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain) throws IOException, javax.servlet.ServletException
doFilter
in interface javax.servlet.Filter
servletRequest
- HTTP servlet requestservletResponse
- HTTP servlet responsefilterChain
- filter chainIOException
- possibly thrown by other filter/servlet in the chainjavax.servlet.ServletException
- possibly thrown by other filter/servlet in the chainprotected boolean shouldBeReported(javax.servlet.http.HttpServletRequest request, long requestNanoTime, List<Split> splits)
getThreshold(javax.servlet.http.HttpServletRequest)
(which by default returns value configured
in web.xml
)request
- HTTP servlet requestrequestNanoTime
- actual HTTP request nano timesplits
- all splits started for the requesttrue
, if request should be reported as over thresholdprotected long getThreshold(javax.servlet.http.HttpServletRequest request)
reportThresholdNanos
(already converted to ns).request
- HTTP Requestpublic Manager getManager()
public void destroy()
destroy
in interface javax.servlet.Filter
Copyright © 2019. All rights reserved.