Class DropwizardMetricsModule
- java.lang.Object
-
- com.google.inject.AbstractModule
-
- ratpack.guice.ConfigurableModule<DropwizardMetricsConfig>
-
- ratpack.dropwizard.metrics.DropwizardMetricsModule
-
- All Implemented Interfaces:
com.google.inject.Module
public class DropwizardMetricsModule extends ConfigurableModule<DropwizardMetricsConfig>
An extension module that provides support for Dropwizard Metrics.To use it one has to register the module and enable the required functionality by chaining the various configuration options. For example, to enable the capturing and reporting of metrics to
DropwizardMetricsConfig.jmx(Action)
one would write: (Groovy DSL)import ratpack.dropwizard.metrics.DropwizardMetricsModule import static ratpack.groovy.Groovy.ratpack ratpack { bindings { module new DropwizardMetricsModule(), { it.jmx() } } }
To enable the capturing and reporting of metrics to JMX and the console, one would write: (Groovy DSL)
import ratpack.dropwizard.metrics.DropwizardMetricsModule import static ratpack.groovy.Groovy.ratpack ratpack { bindings { module new DropwizardMetricsModule(), { it.jmx().console() } } }
External Configuration
The module can also be configured via external configuration using the ratpack-config extension. For example, to enable the capturing and reporting of metrics to jmx via an external property file which can be overridden with system properties one would write: (Groovy DSL)
import com.google.common.collect.ImmutableMap import ratpack.dropwizard.metrics.DropwizardMetricsModule import ratpack.dropwizard.metrics.DropwizardMetricsConfig import ratpack.config.ConfigData import static ratpack.groovy.Groovy.ratpack ratpack { serverConfig { props(ImmutableMap.of("metrics.jmx.enabled", "true")) // for demo purposes we are using a map to easily see the properties being set sysProps() require("/metrics", DropwizardMetricsConfig) } bindings { module DropwizardMetricsModule } }
Metric Collection
By default
Timer
metrics are collected for all requests received andCounter
metrics for response codes. The module adds a defaultRequestTimingHandler
to the handler chain before any user handlers. This means that response times do not take any framework overhead into account and purely the amount of time spent in handlers. It is important that the module is registered first in the modules list to ensure that all handlers are included in the metric.The module also adds a default
BlockingExecTimingInterceptor
to the execution path. This will add timers that will account for time spent on blocking io calls.Both the request timing handler and the blocking execution timing interceptor can be disabled:
import ratpack.dropwizard.metrics.DropwizardMetricsModule import static ratpack.groovy.Groovy.ratpack ratpack { bindings { module new DropwizardMetricsModule(), { it.requestTimingMetrics(false).blockingTimingMetrics(false) } } handlers { all { render "" } } }
Additional custom metrics can be registered with the provided
MetricRegistry
instanceExample custom metrics: (Groovy DSL)
import ratpack.dropwizard.metrics.DropwizardMetricsModule import com.codahale.metrics.MetricRegistry import static ratpack.groovy.Groovy.ratpack ratpack { bindings { module new DropwizardMetricsModule(), { it.jmx() } } handlers { MetricRegistry metricRegistry -> all { metricRegistry.meter("my custom meter").mark() render "" } } }
Custom metrics can also be added via the Metrics annotations (
Metered
,Timed
andGauge
) to any Guice injected classes.- See Also:
- Dropwizard Metrics
-
-
Field Summary
Fields Modifier and Type Field Description static String
RATPACK_METRIC_REGISTRY
-
Constructor Summary
Constructors Constructor Description DropwizardMetricsModule()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
configure()
-
Methods inherited from class ratpack.guice.ConfigurableModule
configure, createConfig, defaultConfig, setConfig
-
Methods inherited from class com.google.inject.AbstractModule
addError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBinding
-
-
-
-
Field Detail
-
RATPACK_METRIC_REGISTRY
public static final String RATPACK_METRIC_REGISTRY
- See Also:
- Constant Field Values
-
-