22 Dropwizard Metrics
ratpack-dropwizard-metrics jar provides integration with Dropwizard Metrics library.
Dropwizard Metrics is one of the best metrics libraries out there for the JVM. It provides a toolkit of metric types and metric reporters that will give a deep insight into your application’s performance, whether that be at development time or real time in production. It allows you to easily capture statistics like the number of requests served or response times, and also more generic information like the state of your internal collections, queues or how many times some portion of code is being executed. By measuring your code you will know exactly what your code is doing when it runs and be able to make informed optimization decisions.
Ratpack’s integration with Dropwizard Metrics means that many of these key metrics are captured already for you, simply by registering the Guice module. Should you require further insight then Ratpack also makes it easy for you to capture additional metrics using the library’s many metric types and then report all of these metrics to your required output using the library’s metric reporters.
DropwizardMetricsModule for detailed usage information.
1.22 Built-in metrics
Ratpack provides built-in metric collectors for key metrics. When metrics are enabled within your application using
DropwizardMetricsModule, the built,in metric collectors will automatically be enabled too.
Ratpack has built-in metric collectors for:
- Request timing
- Background operation timing
Ratpack also has support for Dropwizard Metric’s JVM instrumentation. See
DropwizardMetricsConfig.jvmMetrics(boolean) for usage information.
2.22 Custom metrics
Ratpack enables you to capture your own application metrics in two ways:
- Obtaining the
MetricRegistryvia dependency injection or context registry lookup and registering your own metrics with it.
- Add metrics annotations to your Guice injected classes.
DropwizardMetricsModule for more details.
3.22 Reporting metrics
Ratpack supports metric reporters for the following outputs:
For an example of how to consume real-time metrics with websockets, see the example-books project.