JMX Metrics Filter

Servlet filter implementation for extracting metrics and exposing them on JMX.

License

License

Categories

Categories

Metrics Application Testing & Monitoring Monitoring
GroupId

GroupId

co.aurasphere.metrics
ArtifactId

ArtifactId

jmx-metrics-filter-jdk5
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

JMX Metrics Filter
Servlet filter implementation for extracting metrics and exposing them on JMX.
Project URL

Project URL

https://github.com/aurasphere/jmx-metrics-filter
Project Organization

Project Organization

Aurasphere
Source Code Management

Source Code Management

https://github.com/aurasphere/jmx-metrics-filter

Download jmx-metrics-filter-jdk5

How to add to project

<!-- https://jarcasting.com/artifacts/co.aurasphere.metrics/jmx-metrics-filter-jdk5/ -->
<dependency>
    <groupId>co.aurasphere.metrics</groupId>
    <artifactId>jmx-metrics-filter-jdk5</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/co.aurasphere.metrics/jmx-metrics-filter-jdk5/
implementation 'co.aurasphere.metrics:jmx-metrics-filter-jdk5:1.0.0'
// https://jarcasting.com/artifacts/co.aurasphere.metrics/jmx-metrics-filter-jdk5/
implementation ("co.aurasphere.metrics:jmx-metrics-filter-jdk5:1.0.0")
'co.aurasphere.metrics:jmx-metrics-filter-jdk5:jar:1.0.0'
<dependency org="co.aurasphere.metrics" name="jmx-metrics-filter-jdk5" rev="1.0.0">
  <artifact name="jmx-metrics-filter-jdk5" type="jar" />
</dependency>
@Grapes(
@Grab(group='co.aurasphere.metrics', module='jmx-metrics-filter-jdk5', version='1.0.0')
)
libraryDependencies += "co.aurasphere.metrics" % "jmx-metrics-filter-jdk5" % "1.0.0"
[co.aurasphere.metrics/jmx-metrics-filter-jdk5 "1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.26
io.dropwizard.metrics : metrics-core jar 3.2.6

provided (1)

Group / Artifact Type Version
javax.servlet : javax.servlet-api jar 3.0.1

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19
ch.qos.logback : logback-classic jar 1.2.3

Project Modules

There are no modules declared in this project.

Travis Maven Central Javadocs Maintainability Test Coverage Join the chat at https://gitter.im/jmx-metrics-filter/community Donate

JMX Metrics Filter

Servlet filter implementation for extracting metrics and exposing them on JMX. The filter will expose a bean for each combination of endpoint/HTTP status code with the invocation time stats (average, minimum, maximum...).

Two artifacts are provided:

  • jmx-metrics-filter-jdk8, backward compatibile with Java 8, based on micrometer.io
  • jmx-metrics-filter-jdk5, backward compatibile with Java 5, based on metrics.dropwizard.io

Usage

To import the library using Maven, add this to your pom.xml (changing the * with the version you want to use):

<dependency>
    <groupId>co.aurasphere.metrics</groupId>
    <artifactId>jmx-metrics-filter-jdk*</artifactId>
    <version>1.0.0</version>
</dependency>

Web application

To use the filter in a web application, add it on your web.xml:

<filter>
    <filter-name>metrics-filter</filter-name>
    <filter-class>co.aurasphere.metrics.jdk*.JmxMetricsFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>metrics-filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Servlet container

To use the filter in a Servlet container, you have to manually add the jar and their dependencies to the container classpath:

jmx-metrics-filter-jdk5 jmx-metrics-filter-jdk8
slf4j-api-1.7.26.jar slf4j-api-1.7.26.jar
LatencyUtils-2.0.3.jar LatencyUtils-2.0.3.jar
metrics-core-3.2.6.jar metrics-core-4.0.3.jar
metrics-jmx-3.2.6.jar metrics-jmx-4.0.3.jar
micrometer-core-1.1.4.jar
micrometer-registry-jmx-1.1.4.jar

Then, you have to register the filter on the container. Follows an example on Tomcat:

<filter>
    <filter-name>metrics-filter</filter-name>
    <filter-class>co.aurasphere.metrics.jdk*.JmxMetricsFilter</filter-class>
    <init-param>
        <param-name>contexts</param-name>
        <param-value>/web-test,/web-test-2</param-value>
    </init-param>
    <init-param>
        <param-name>whitelist</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>metrics-filter</filter-name>
    <url-pattern>*.html</url-pattern>
    <url-pattern>*.do</url-pattern>
    <url-pattern>/*</url-pattern>
</filter-mapping>

When using the filter on a container, you can tweak it further with the following init-param:

  • contexts, a list of comma-separed of web application contexts intercepted by this filter. If not specified, the filter will intercept requests on every context.
  • whitelist, specifies whether or not the specified contexts should be the only ones intercepted (true) or the only ones excluded by the filter (false). Defaults to true if not specified.

Spring Boot

To use the filter in a Spring Boot application, simply register the filter as a bean:

@Bean
public Filter jmxMetricsFilter() {
    return new JmxMetricsFilter();
}

Copyright (c) 2019 Donato Rimenti

Versions

Version
1.0.0