Fork me on GitHub

Pippo provides optional integration with Metrics for measuring the responsiveness of your application.

Pippo comes (out of the box) with some reporting backends:

Add the Pippo Metrics dependency

<dependency>
    <groupId>ro.pippo</groupId>
    <artifactId>pippo-metrics</artifactId>
    <version>${pippo.version}</version>
</dependency>

Collecting Metrics

Now you are ready to start annotating your route handler methods or controller methods.

You have several choices in the collection of metrics:

  • Counted A counter increments (and optionally decrements) when a method is executed.
  • Metered A meter measures the rate of events over time (e.g., “requests per second”). In addition to the mean rate, meters also track 1-, 5-, and 15-minute moving averages.
  • Timed A timer measures both the rate that a particular piece of code is called and the distribution of its duration.
  1. Start by sprinkling @Counted, @Metered, or @Timed on some of your controller methods.
  2. Start up VisualVM (and install the MBeans plugin) or JConsole.
  3. Browse your app and refresh the collected metrics.

See below how to add a metric (meter) on a route handler

GET("/", new RouteHandler() {

    @Metered("HelloWorld")
    @Override
    public void handle(RouteContext routeContext) {
        routeContext.send("Hello World");
    }

});

Other possible variants

// metered route
GET("/metered", new MeteredHandler("HelloWorld", routeContext -> routeContext.send("Metered !!!")));
GET("/", new RouteHandler() {

    @Metered
    @Override
    public void handle(RouteContext routeContext) {
        routeContext.send("Hello World");
    }

}).named("HelloWorld"); // <<< create a route with a name

in this case the metric name is the route name (“HelloWorld”) because we have a named route and the metric name is missing for @Metered annotation.

GET("/", new MyHandler());

static class MyHandler implements RouteHandler {

    @Metered
    public void handle(RouteContext routeContext) {
        routeContext.render("hello"); // render "hello" template
    }

}

in this case the metric name is “MyHandler.handle” (route handler class name and method name)

See below how to add a metric (time) in a controller

public class ContactsController extends Controller {

    @Timed
    public void index() {
        getResponse().render("crud/contacts");
    }

}

in this case the metric name is “ContactsController.index” (controller class name and method name)

Collecting Additional Metrics

JVM Metrics

You may optionally enable JVM-level details reporting by setting metrics.jvm.enabled=true in your application.properties file.

metrics.jvm.enabled = true

Reporting Metrics via MBeans for VisualVM, JConsole, or JMX

If you want to expose your metrics to VisualVM, JConsole, or JMX you must enable the MBeans reporter in your application.properties file.

metrics.mbeans.enabled = true

You can view the collected metrics using VisualVM (with the MBeans plugin installed) or using JConsole.