bogorman / metrics-scala

The scala API for Coda Hale's Metrics.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Metrics-Scala

Capturing JVM- and application-level metrics. So you know what's going on.

This is the Scala API for Coda Hale's Metrics library.

Initially this project started out as a line for line copy of the Metrics-scala module, released for multiple scala versions. Metrics dropped the scala module in version 3.0.0 and this project continued separately with the help of @scullxbones.

Contents

Usage

Metrics-scala provides an easy way to create metrics and health checks in Scala. Metrics-core requires an application wide MetricRegistry. Create an Instrumented trait that refers to that registry and extends the InstrumentedBuilder trait.

object YourApplication {
  /** The application wide metrics registry. */
  val metricRegistry = new com.codahale.metrics.MetricRegistry()
}
trait Instrumented extends nl.grons.metrics.scala.InstrumentedBuilder {
  val metricRegistry = YourApplication.metricRegistry
}

Now you can create metrics by using the metrics metrics builder.

class Example(db: Database) extends Instrumented {
  private[this] val loading = metrics.timer("loading")

  def loadStuff(): Seq[Row] = loading.time {
    db.fetchRows()
  }
}

For more detailed information see the manual. For more information on Metrics-core 3.x, please see the documentation.

See the change log for API changes compared to the 2.x versions.

Features

  • Easy creation of all metrics types.
  • Easy creation of Health Checks.
  • Almost invisible syntax for using timers (see example above).
  • Scala specific methods on metrics (e.g. += on counters).
  • Derives proper metrics names for Scala objects and closures.
  • Actor support.
  • Future support.

Available versions (abbreviated)

This table shows the most relevant versions of metrics-scala. For the full list, including the Scala 2.9 versions, see all available version.

Metrics-
scala
version
Metrics-
core
version
Akka-
version
Scala version
2.10 2.11
2.1.5 2.1.5
3.2.0 3.0.2
3.2.0_a2.1 3.0.2 2.1.4
3.2.0_a2.2 3.0.2 2.2.4
3.2.0_a2.3 3.0.2 2.3.2

If you need another version mix please open an issue, or sent an email to the metrics mailing list.

Note: If Akka has a newer minor-version, you can use that instead of the version metrics was build against.

Download

SBT:

libraryDependencies += "nl.grons" %% "metrics-scala" % "3.2.0_a2.3"

Maven:

<properties>
    <scala.version>2.11.0</scala.version>
    <scala.dep.version>2.11</scala.dep.version>
</properties>
<dependency>
    <groupId>nl.grons</groupId>
    <artifactId>metrics-scala_${scala.dep.version}</artifactId>
    <version>3.2.0_a2.3</version>
</dependency>

Support

If you find a bug, please open an issue, better yet: send a pull request. For questions, please sent an email to the metrics mailing list.

License

Copyright (c) 2010-2012 Coda Hale, Yammer.com (before 3.0.0)

Copyright (c) 2013-2014 Erik van Oosten (3.0.0 and later)

Published under Apache Software License 2.0, see LICENSE

About

The scala API for Coda Hale's Metrics.

License:Apache License 2.0