public class DropwizardMetricsModule extends ConfigurableModule<DropwizardMetricsConfig>
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(ratpack.func.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() } } }
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 } }
By default Timer
metrics are collected for all requests received and Counter
metrics for response codes.
The module adds a default RequestTimingHandler
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
instance
Example 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
and Gauge
)
to any Guice injected classes.
Modifier and Type | Field and Description |
---|---|
static String |
RATPACK_METRIC_REGISTRY |
Constructor and Description |
---|
DropwizardMetricsModule() |
Modifier and Type | Method and Description |
---|---|
protected void |
configure() |
configure, createConfig, defaultConfig, setConfig
addError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBinding
public static final String RATPACK_METRIC_REGISTRY
protected void configure()
configure
in class AbstractModule