Ninja provides optional integration with Metrics for measuring the responsiveness of your application.
<dependency>
<groupId>org.ninjaframework</groupId>
<artifactId>ninja-metrics</artifactId>
<version>${ninja.version}</version>
</dependency>
@Singleton
public class Module extends AbstractModule {
@Override
protected void configure() {
install(new MetricsModule());
}
}
package conf;
import ninja.metrics.InstrumentedNinja;
public class Ninja extends InstrumentedNinja {
}
Now you are ready to start annotating your controllers or any other methods.
You have several choices in the collection of metrics:
package controllers;
@Singleton
public class AppController {
@Timed
public Result index() {
return Results.html();
}
}
If you want to instrument your NinjaCache, Ninja-Metrics supports instrumenting both the EhCache and the Memcached implementations.
In your application.conf file specify:
cache.implementation = ninja.metrics.InstrumentedEhCache
or
cache.implementation = ninja.metrics.InstrumentedMemcached
If you want to expose your metrics to VisualVM, JConsole, or JMX you must enable the MBeans reporter in your application.conf file.
metrics.mbeans.enabled = true
You can view the collected metrics using VisualVM (with the MBeans plugin installed) or using JConsole.
Ninja Metrics supports reporting to Graphite.
Add the following dependency to your application pom.xml.
<dependency>
<groupId>org.ninjaframework</groupId>
<artifactId>ninja-metrics-graphite</artifactId>
<version>${ninja.version}</version>
</dependency>
Bind the Graphite integration in your Module.java.
@Singleton
public class Module extends AbstractModule {
@Override
protected void configure() {
bind(NinjaGraphite.class);
}
}
Add the following settings to your application.conf.
metrics.graphite.enabled = true metrics.graphite.address = graphite.example.com metrics.graphite.port = 2003 metrics.graphite.pickled = false metrics.graphite.period = 60s
By default all metrics will be prefixed with the hostname. To specify a custom prefix add the following setting.
metrics.graphite.prefix = my.custom.prefix
Ninja Metrics supports reporting to Ganglia.
Add the following dependency to your application pom.xml.
<dependency>
<groupId>org.ninjaframework</groupId>
<artifactId>ninja-metrics-ganglia</artifactId>
<version>${ninja.version}</version>
</dependency>
Bind the Ganglia integration in your Module.java.
@Singleton
public class Module extends AbstractModule {
@Override
protected void configure() {
bind(NinjaGanglia.class);
}
}
Add the following settings to your application.conf.
metrics.ganglia.enabled = true metrics.ganglia.address = ganglia.example.com metrics.ganglia.port = 8649 metrics.ganglia.period = 60s
Ninja Metrics supports reporting to InfluxDB.
Add the following dependency to your application pom.xml.
<dependency>
<groupId>org.ninjaframework</groupId>
<artifactId>ninja-metrics-influxdb</artifactId>
<version>${ninja.version}</version>
</dependency>
Bind the InfluxDB integration in your Module.java.
@Singleton
public class Module extends AbstractModule {
@Override
protected void configure() {
bind(NinjaInfluxDB.class);
}
}
Add the following settings to your application.conf.
metrics.influxdb.enabled = true metrics.influxdb.address = localhost metrics.influxdb.port = 8086 metrics.influxdb.database = mydb metrics.influxdb.username = root metrics.influxdb.password = root metrics.influxdb.period = 60s
Librato is a cloud-based metrics database and dashboard service.
Add the following dependency to your application pom.xml.
<dependency>
<groupId>org.ninjaframework</groupId>
<artifactId>ninja-metrics-librato</artifactId>
<version>${ninja.version}</version>
</dependency>
Bind the Librato integration in your Module.java.
@Singleton
public class Module extends AbstractModule {
@Override
protected void configure() {
bind(NinjaLibrato.class);
}
}
Add the following settings to your application.conf.
metrics.librato.enabled = true metrics.librato.username = person@example.com metrics.librato.apikey = 12345cafebabe metrics.librato.period = 60s