diff options
author | Diego Parra <dparra@despegar.com> | 2013-05-03 17:06:10 -0300 |
---|---|---|
committer | Diego Parra <dparra@despegar.com> | 2013-05-03 17:06:10 -0300 |
commit | 2caece9ef7574406c548b4a1f333de4c9579b3a2 (patch) | |
tree | 9536c6b95fac7dca34a5c2dae27d931b88694632 /src/main/scala/kamon/metric/Metrics.scala | |
parent | fc8a371548d9de3c5e0719dcfcf041ca31bc2227 (diff) | |
download | Kamon-2caece9ef7574406c548b4a1f333de4c9579b3a2.tar.gz Kamon-2caece9ef7574406c548b4a1f333de4c9579b3a2.tar.bz2 Kamon-2caece9ef7574406c548b4a1f333de4c9579b3a2.zip |
Initial Commit Kamon
Diffstat (limited to 'src/main/scala/kamon/metric/Metrics.scala')
-rw-r--r-- | src/main/scala/kamon/metric/Metrics.scala | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main/scala/kamon/metric/Metrics.scala b/src/main/scala/kamon/metric/Metrics.scala new file mode 100644 index 00000000..ecfa0ec6 --- /dev/null +++ b/src/main/scala/kamon/metric/Metrics.scala @@ -0,0 +1,49 @@ +package kamon.metric + +import com.yammer.metrics.core.{MetricName, MetricsRegistry} +import scala.collection.mutable.{HashMap,SynchronizedMap} +import com.yammer.metrics.scala.{Meter, Counter, MetricsGroup, Timer} +import com.yammer.metrics.reporting.{ConsoleReporter, JmxReporter} +import scala.collection.mutable +import java.util.concurrent.TimeUnit + +class Metrics { + private lazy val metricsRegistry: MetricsRegistry = new MetricsRegistry() + private lazy val metricsGroup = new MetricsGroup(this.getClass, metricsRegistry) + + private lazy val meters = new mutable.HashMap[String, Meter] + private lazy val timers = new HashMap[String, Timer] with SynchronizedMap[String, Timer] + private lazy val counters = new HashMap[String, Counter] with SynchronizedMap[String, Counter] + + + + val consoleReporter = ConsoleReporter.enable(metricsRegistry, 1, TimeUnit.SECONDS) + val newrelicReport = new NewRelicReporter(metricsRegistry, "newrelic-reporter"); + newrelicReport.run() + newrelicReport.start(1, TimeUnit.SECONDS) + + def incrementCounter(key: String) { + counters.getOrElseUpdate(key, (metricsGroup.counter(s"${key}-counter"))).count + } + + def markMeter(key: String) { + meters.getOrElseUpdate(key, metricsGroup.meter(s"${key}-meter", "actor", "actor-message-counter", TimeUnit.SECONDS)).mark() + } + + def trace[T](key: String)(f: => T): T = { + val timer = timers.getOrElseUpdate(key, (metricsGroup.timer(s"${key}-timer")) ) + timer.time(f) + } + + def markAndCountMeter[T](key: String)(f: => T): T = { + markMeter(key) + f + } + + def traceAndCount[T](key: String)(f: => T): T = { + incrementCounter(key) + trace(key) { + f + } + } +}
\ No newline at end of file |