All Projects → rlazoti → Finagle Metrics

rlazoti / Finagle Metrics

Licence: mit
Easy way to send Finagle metrics to Codahale Metrics library

Programming Languages

scala
5932 projects

Labels

Projects that are alternatives of or similar to Finagle Metrics

Outwatch
A purely functional and reactive UI framework
Stars: ✭ 376 (+817.07%)
Mutual labels:  sbt
Sbt Docker
Create Docker images directly from sbt
Stars: ✭ 689 (+1580.49%)
Mutual labels:  sbt
E
A zero-dependency micro library to deal with errors
Stars: ✭ 21 (-48.78%)
Mutual labels:  sbt
Sbt
sbt, the interactive build tool
Stars: ✭ 4,437 (+10721.95%)
Mutual labels:  sbt
Scalafix
Refactoring and linting tool for Scala
Stars: ✭ 597 (+1356.1%)
Mutual labels:  sbt
Scala Steward
🤖 A bot that helps you keep your Scala projects up-to-date
Stars: ✭ 812 (+1880.49%)
Mutual labels:  sbt
Scastie
An interactive playground for Scala
Stars: ✭ 319 (+678.05%)
Mutual labels:  sbt
Sbt Play Gulp
Gulp asset pipeline for Play Framework
Stars: ✭ 38 (-7.32%)
Mutual labels:  sbt
Sbt Updates
sbt plugin that can check Maven and Ivy repositories for dependency updates
Stars: ✭ 653 (+1492.68%)
Mutual labels:  sbt
Sbt Ignore Play Generated
Configure linters and coverage tools to ignore Play's generated source files.
Stars: ✭ 10 (-75.61%)
Mutual labels:  sbt
Sbt Buildinfo
I know this because build.sbt knows this.
Stars: ✭ 486 (+1085.37%)
Mutual labels:  sbt
Sbt Release
A release plugin for sbt
Stars: ✭ 582 (+1319.51%)
Mutual labels:  sbt
Sbt Scripting
Getting started tutorial for scripting using sbt.
Stars: ✭ 9 (-78.05%)
Mutual labels:  sbt
Xsbt Web Plugin
Servlet support for sbt
Stars: ✭ 381 (+829.27%)
Mutual labels:  sbt
Scala Cypher Dsl
A type-safe Cypher Query Language DSL for Scala.
Stars: ✭ 34 (-17.07%)
Mutual labels:  sbt
Scalnet
A Scala wrapper for Deeplearning4j, inspired by Keras. Scala + DL + Spark + GPUs
Stars: ✭ 342 (+734.15%)
Mutual labels:  sbt
Scala Logging
Convenient and performant logging library for Scala wrapping SLF4J.
Stars: ✭ 804 (+1860.98%)
Mutual labels:  sbt
Play Reactive Slick
This is Play Template with a nice User Interface. If you want to use Play as web framework and Postgres as Database then this demo project can be used as a starting point for your application.
Stars: ✭ 40 (-2.44%)
Mutual labels:  sbt
Rhodddoobie
My little sandbox for playing around with the FP + OOP + DDD combination, in particular using Rho, doobie, Docker, testing, etc in a project.
Stars: ✭ 38 (-7.32%)
Mutual labels:  sbt
Swagger Codegen Play Scala
Swagger client generator which is based on the PlayWS library
Stars: ✭ 9 (-78.05%)
Mutual labels:  sbt

finagle-metrics

Easy way to send Finagle metrics to Codahale Metrics library.

Overview

finagle-metrics enables your finagle based application to send its metrics to Codahale Metrics library instead of the default metrics (finagle-stats).

Build

$ git clone https://github.com/rlazoti/finagle-metrics.git
$ cd finagle-metrics
$ sbt package

Test

$ sbt test

Setup

Finagle-metrics is available on OSS Sonatype.

So everything you need to do is add the sbt dependency like:

"com.github.rlazoti" %% "finagle-metrics" % "0.0.13"

or

"com.github.rlazoti" % "finagle-metrics_2.12" % "0.0.13"

Note that finagle-metrics is cross-published for both 2.11 and 2.12 so you can use 2.11 scala version as well.

Usage

Using twitter-server

If you're using twitter-server to create your finagle services, everything you need to do is just adding the finagle-metrics dependency 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.

Including your own metrics

You can include your own metrics through the statsReceiver field of TwitterServer, so your metrics will be sent to Codahale Metrics as well.

Including your own metrics through Codahale Metrics

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()

Reporting

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)

And an example using JmxReporter.

import com.codahale.metrics.JmxReporter
import com.twitter.finagle.metrics.MetricsStatsReceiver

val reporter: JmxReporter = JmxReporter.forRegistry(MetricsStatsReceiver.metrics)
                                       .build()

reporter.start()

Full Example

Let's create a full example that reports its metrics to console each five seconds (or take a look at the example folder).

Firstly, let's create the build.sbt:

name := "finagle-metrics-example"

version := "0.0.1-SNAPSHOT"

scalaVersion := "2.12.1"

resolvers += "twttr" at "https://maven.twttr.com/"
resolvers += Resolver.sonatypeRepo("public")

libraryDependencies ++= Seq(
  "com.twitter"        %% "twitter-server"  % "20.3.0",
  "com.github.rlazoti" %% "finagle-metrics" % "0.0.13"
)

Then the App.scala:

import com.codahale.metrics.ConsoleReporter
import com.twitter.finagle.{ Http, Service }
import com.twitter.finagle.metrics.MetricsStatsReceiver
import com.twitter.finagle.http.{ Request, Response, Status }
import com.twitter.io.Charsets
import com.twitter.server.TwitterServer
import com.twitter.util.{ Await, Future }
import java.util.concurrent.TimeUnit

object App extends TwitterServer {

  val service = new Service[Request, Response] {
    def apply(request: Request) = {
      val response = Response(request.version, Status.Ok)
      response.contentString = "hello"
      Future.value(response)
    }
  }

  val reporter = ConsoleReporter
    .forRegistry(MetricsStatsReceiver.metrics)
    .convertRatesTo(TimeUnit.SECONDS)
    .convertDurationsTo(TimeUnit.MILLISECONDS)
    .build

  def main() = {
    val server = Http.serve(":8080", service)
    reporter.start(5, TimeUnit.SECONDS)

    onExit { server.close() }

    Await.ready(server)
  }

}

That's all Folks! :)

Author

Rodrigo Lazoti - [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].