Easy way to send Finagle metrics to Codahale Metrics library.
finagle-metrics enables your finagle based application to send its metrics to Codahale Metrics library instead of the default metrics (finagle-stats).
$ git clone https://github.com/rlazoti/finagle-metrics.git
$ cd finagle-metrics
$ sbt package
$ sbt test
To install it locally, run:
$ git checkout tags/version-0.0.1 -b version-0.0.1
$ sbt publish-local
And add the sbt dependency as:
"com.github.rlazoti" %% "finagle-metrics" % "0.0.1"
or
"com.github.rlazoti" % "finagle-metrics_2.11" % "0.0.1"
If you're using twitter-server to create your finagle services, everything you need to do is just adding the finagle-metrics jar to your project.
You don't need to add the finagle-stats to your project, but both libraries will work together without any issue if you need it.
You can include your own metrics through the statsReceiver field of TwitterServer, so your metrics will be sent to Codahale Metrics as well.
You can obtain an instance of MetricRegistry class through the field metrics of MetricsStatsReceiver.
import com.twitter.finagle.metrics.MetricsStatsReceiver
val myCustomMeter = MetricsStatsReceiver.metrics.meter("my-custom-meter")
myCustomMeter.mark()
Codahale Metrics library has reporters for many diferent outputs.
Let's take the GraphiteReporter as example.
import com.codahale.metrics.graphite.{Graphite, GraphiteReporter}
import com.twitter.finagle.metrics.MetricsStatsReceiver
import java.util.concurrent.TimeUnit;
val graphite = new Graphite(new InetSocketAddress("graphite.example.com", 2003));
val reporter = GraphiteReporter.forRegistry(MetricsStatsReceiver.metrics)
.prefixedWith("finagle-service.example.com")
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build(graphite)
reporter.start(1, TimeUnit.MINUTES)