Package io.prometheus.client.filter
Class MetricsFilter
- java.lang.Object
-
- io.prometheus.client.filter.MetricsFilter
-
- All Implemented Interfaces:
javax.servlet.Filter
public class MetricsFilter extends java.lang.Object implements javax.servlet.FilterThe MetricsFilter class exists to provide a high-level filter that enables tunable collection of metrics for Servlet performance.The Histogram name itself is required, and configured with a
metric-nameinit parameter.The help parameter, configured with the
helpinit parameter, is not required but strongly recommended.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-componentsinit parameter. Any number provided that is less than 1 will provide the full path granularity (warning, this may affect performance).The Histogram buckets can be configured with a
bucketsinit parameter whose value is a comma-separated list of validdoublevalues.<filter> <filter-name>prometheusFilter</filter-name> <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> <init-param> <param-name>help</param-name> <param-value>The time taken fulfilling servlet requests</param-value> </init-param> <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> <init-param> <param-name>path-components</param-name> <param-value>0</param-value> </init-param> </filter>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.StringBUCKET_CONFIG_PARAMprivate double[]bucketsprivate java.lang.Stringhelp(package private) static java.lang.StringHELP_PARAMprivate Histogramhistogram(package private) static java.lang.StringMETRIC_NAME_PARAMprivate java.lang.StringmetricName(package private) static java.lang.StringPATH_COMPONENT_PARAM(package private) intpathComponents
-
Constructor Summary
Constructors Constructor Description MetricsFilter()MetricsFilter(java.lang.String metricName, java.lang.String help, java.lang.Integer pathComponents, double[] buckets)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()voiddoFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain)private java.lang.StringgetComponents(java.lang.String str)voidinit(javax.servlet.FilterConfig filterConfig)private booleanisEmpty(java.lang.String s)
-
-
-
Field Detail
-
PATH_COMPONENT_PARAM
static final java.lang.String PATH_COMPONENT_PARAM
- See Also:
- Constant Field Values
-
HELP_PARAM
static final java.lang.String HELP_PARAM
- See Also:
- Constant Field Values
-
METRIC_NAME_PARAM
static final java.lang.String METRIC_NAME_PARAM
- See Also:
- Constant Field Values
-
BUCKET_CONFIG_PARAM
static final java.lang.String BUCKET_CONFIG_PARAM
- See Also:
- Constant Field Values
-
histogram
private Histogram histogram
-
pathComponents
int pathComponents
-
metricName
private java.lang.String metricName
-
help
private java.lang.String help
-
buckets
private double[] buckets
-
-
Method Detail
-
isEmpty
private boolean isEmpty(java.lang.String s)
-
getComponents
private java.lang.String getComponents(java.lang.String str)
-
init
public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException- Specified by:
initin interfacejavax.servlet.Filter- Throws:
javax.servlet.ServletException
-
doFilter
public void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain) throws java.io.IOException, javax.servlet.ServletException- Specified by:
doFilterin interfacejavax.servlet.Filter- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
destroy
public void destroy()
- Specified by:
destroyin interfacejavax.servlet.Filter
-
-