public class CodaHaleMetricsModule extends ConfigurableModule<CodaHaleMetricsModule.Config>
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 CodaHaleMetricsModule.Config.jmx(ratpack.func.Action)
one would write: (Groovy DSL)
import ratpack.codahale.metrics.CodaHaleMetricsModule
import static ratpack.groovy.Groovy.ratpack
ratpack {
bindings {
module new CodaHaleMetricsModule(), { it.jmx() }
}
}
To enable the capturing and reporting of metrics to JMX and the console, one would write: (Groovy DSL)
import ratpack.codahale.metrics.CodaHaleMetricsModule
import static ratpack.groovy.Groovy.ratpack
ratpack {
bindings {
module new CodaHaleMetricsModule(), { it.jmx().console() }
}
}
import com.google.common.collect.ImmutableMap
import ratpack.codahale.metrics.CodaHaleMetricsModule
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", CodaHaleMetricsModule.Config)
}
bindings {
module CodaHaleMetricsModule
}
}
By default Timer metrics are collected for all requests received and Counter metrics for response codes.
The module adds a 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.
Additional custom metrics can be registered with the provided MetricRegistry instance
Example custom metrics: (Groovy DSL)
import ratpack.codahale.metrics.CodaHaleMetricsModule
import com.codahale.metrics.MetricRegistry
import static ratpack.groovy.Groovy.ratpack
ratpack {
bindings {
module new CodaHaleMetricsModule(), { 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 | Class and Description |
|---|---|
static class |
CodaHaleMetricsModule.Config
The configuration object for
CodaHaleMetricsModule. |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
RATPACK_METRIC_REGISTRY |
| Constructor and Description |
|---|
CodaHaleMetricsModule() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
configure() |
configure, createConfig, defaultConfig, setConfigaddError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBindingpublic static final java.lang.String RATPACK_METRIC_REGISTRY