This PR provides a wrapper around Dropwizard's metrics library.
Fields or Methods tagged with @ExportMetric can be registered to emit metrics to a variety of sources via Reporters. In this PR, wrappers are provided for emitting metrics to SL4J, JMX, Graphite, and Ganglia. Reporters can be configured via orbit.yaml like so:
orbit.metrics.reporters:
- !!com.ea.orbit.metrics.config.Slf4jReporterConfig
period: 1
periodUnit: 'MINUTES'
prefix: 'chat.chat-backend'
- !!com.ea.orbit.metrics.config.JmxReporterConfig {}
Standard configuration management tools can be used to modify the prefix on a host-by-host manner when deploying by modifying this file.
An Orbit Container Module is provided to setup metrics on the JVM if actors is not being used. The Actors Module will also attempt to setup metrics. If Container is not being used, MetricsManager can be provided a set of ReporterConfig objects using the initializeMetrics() method. This should be done before Stage startup if actors is being used.
Metrics must be registered using the MetricsManager registerExportedMetrics method. A instanceId may be provided so that instance metrics can be setup.
Metrics must be uniquely named. Currently, metrics are named using the name of the class they are defined in plus the name provided via the ExportMetric annotation. For example a metric in ca.fieldflux.awesomeapp.neatclass with a field annotated with
@ExportMetric(name="coolmetric")
would generate a metric named:
ca.fieldflux.awesomeapp.neatclass.coolmetric
Instance Metrics can be used where there may be more than one instance of a class and metrics must be tracked per-instance. To mark a metric as an instance metric use:
@ExportMetric(name="coolmetric", isInstanceMetric=true)
and provide an instanceId when registering the object instance. This will insert an instance identifier into the metric name hierarchy like so:
ca.fieldflux.awesomeapp.neatclass.instanceId.coolmetric
An Actors lifetime extension is also provided so that Actors can expose metrics and have them automatically registered and unregistered on actor activation and deactivation respectively.