Metrics bundle hooks into the container and collects statistics at application level. Minnal metrics internally uses Yammer’s metric library and allows you to log the metrics using multiple reporters.
To enable metrics in your service, add minnal-metrics to your maven dependencies.
1 2 3 4 | <dependency>
<groupId>org.minnal</groupId>
<artifactId>minnal-metrics</artifactId>
</dependency>
|
And enable one or more reporters in the container configuration. You will have to overirde the bundle configuration for metrics bundle. Below code shows a sample configuration
1 2 3 4 5 6 7 | # You can override the bundle configurations using bundleOverrides
bundleOverrides:
# The key is the fully qualified name of the bundle class
org.minnal.metrics.MetricsBundle:
# The configuration class must be specified to override the properties
class: org.minnal.metrics.MetricsBundleConfiguration
enableJmxReporter: true
|
The Response time collector collects the response times at route level for each of the applications. It also computes the max, min, mean, rate and percentile information for every route. The collected metrics are logged via the configured Reporters for every incoming request.
The metric key is a combination of application name and the route pattern. For instance, if the route pattern is GET /shopping_carts/{id}/shopping_cart_items
and the application name is shoppingcarts, then the metric key will be
shoppingcarts.shopping_carts.id.shopping_cart_items.GET.responseTime
The Datasource collector collects the connection pool statistics like active/idle/total connections, failed checkins/checkouts/idle tests, uptime etc. and logs them when requested by the reporters.
The datasource metrics are logged using the key,
<application-name>.datasource
JMX Reporter can be enabled from container configuration.
1 2 3 4 5 6 7 | # You can override the bundle configurations using bundleOverrides
bundleOverrides:
# The key is the fully qualified name of the bundle class
org.minnal.metrics.MetricsBundle:
# The configuration class must be specified to override the properties
class: org.minnal.metrics.MetricsBundleConfiguration
enableJmxReporter: true
|
You can view metrics under the JMX domain metrics
using Jconsole.
Graphite Reporter can also be enabled from container configuration. It allows you to customize the graphite host/port, key prefix and poll period.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # You can override the bundle configurations using bundleOverrides
bundleOverrides:
# The key is the fully qualified name of the bundle class
org.minnal.metrics.MetricsBundle:
# The configuration class must be specified to override the properties
class: org.minnal.metrics.MetricsBundleConfiguration
enableJmxReporter: true
enableGraphiteReporter: true
graphiteReporterConfiguration:
graphiteHost: 127.0.0.1
graphitePort: 2003
# The prefix string to prepend to the keys
prefix: my_prefix
# The time interval in seconds to push the metrics to graphite
pollPeriodInSecs: 10
|
The current design doesn’t allow you to create custom reporters in an elegant way. Please raise an issue about your requirement, we will take it up.
Take a look at the class org.minnal.metrics.DataSourcePoolMetricCollector
for inspiration.
You can also publish you application specific metrics using Minnal Metrics. Minnal creates a MetricRegistry per application to which you can publish your metrics. Below is a demonstration of this functionality.
1 2 3 4 5 6 7 8 9 | MetricRegistry metricRegistry = MetricRegistries.getRegistry(application.getConfiguration().getName());
metricRegistry.register(MetricRegistry.name(application.getConfiguration().getName(), "orders", "shipped"),
new Gauge<Integer>() {
@Override
public Integer getValue() {
return Orders.count("status", "shipped");
}
}
);
|