Class MetricsFilter
- All Implemented Interfaces:
javax.servlet.Filter
simpleclient-servlet-jakarta
.
The metric name itself is required, and configured with a metric-name
init parameter.
The help parameter, configured with the help
init parameter, is not required but strongly recommended.
The Histogram buckets can be configured with a buckets
init parameter whose value is a comma-separated
list * of valid double
values. If omitted, the default buckets from Histogram
are used.
By default, this filter will provide metrics that distinguish only 1 level deep for the request path
(including servlet context path), but can be configured with the path-components
init parameter. Any number
provided that is less than 1 will provide the full path granularity (warning, this may affect performance).
The strip-context-path
init parameter can be used to avoid including the leading path components which are
part of the context (i.e. the folder where the servlet is deployed) so that the same project deployed under different
paths can produce the same metrics.
HTTP statuses will be aggregated via Counter. The name for this counter will be derived from the
metric-name
init parameter.
<filter>
<filter-name>prometheusFilter</filter-name>
<!-- This example shows the javax version. For Jakarta you would use -->
<!-- <filter-class>io.prometheus.client.filter.servlet.jakarta.MetricsFilter</filter-class> -->
<filter-class>io.prometheus.client.filter.MetricsFilter</filter-class>
<init-param>
<param-name>metric-name</param-name>
<param-value>webapp_metrics_filter</param-value>
</init-param>
<!-- help is optional, defaults to the message below -->
<init-param>
<param-name>help</param-name>
<param-value>This is the help for your metrics filter</param-value>
</init-param>
<!-- buckets is optional, unless specified the default buckets from io.prometheus.client.Histogram are used -->
<init-param>
<param-name>buckets</param-name>
<param-value>0.005,0.01,0.025,0.05,0.075,0.1,0.25,0.5,0.75,1,2.5,5,7.5,10</param-value>
</init-param>
<!-- path-components is optional, anything less than 1 (1 is the default) means full granularity -->
<init-param>
<param-name>path-components</param-name>
<param-value>1</param-value>
</init-param>
<!-- strip-context-path is optional, defaults to false -->
<init-param>
<param-name>strip-context-path</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<!-- You will most likely want this to be the first filter in the chain
(therefore the first <filter-mapping> in the web.xml file), so that you can get
the most accurate measurement of latency. -->
<filter-mapping>
<filter-name>prometheusFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMetricsFilter
(String metricName, String help, Integer pathComponents, double[] buckets) MetricsFilter
(String metricName, String help, Integer pathComponents, double[] buckets, boolean stripContextPath) -
Method Summary
-
Field Details
-
delegate
-
-
Constructor Details
-
Method Details
-
init
public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException - Specified by:
init
in interfacejavax.servlet.Filter
- Throws:
javax.servlet.ServletException
-
doFilter
public void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain) throws IOException, javax.servlet.ServletException - Specified by:
doFilter
in interfacejavax.servlet.Filter
- Throws:
IOException
javax.servlet.ServletException
-
destroy
public void destroy()- Specified by:
destroy
in interfacejavax.servlet.Filter
-