Permalink
Browse files

upgrade to metrics 2.0

  • Loading branch information...
1 parent 16cdec0 commit a0c173bdc2eb74b6ba776273fa56ca1fbb19f65a @jamesgolick committed Sep 8, 2011
@@ -8,7 +8,7 @@ class StatsdProject(info: ProjectInfo) extends DefaultProject(info)
val jbossRepo = "JBoss Repo" at
"https://repository.jboss.org/nexus/content/repositories/releases"
- val metrics = "com.yammer" %% "metrics" % "1.0.7" withSources()
+ val metrics = "com.yammer" %% "metrics" % "2.0.0-BETA11-SNAPSHOT" withSources()
val specs = "org.scala-tools.testing" %% "specs" % "1.6.6"
val mockito = "org.mockito" % "mockito-all" % "1.8.5"
val netty = "org.jboss.netty" % "netty" % "3.2.4.Final" withSources()
View
@@ -1,42 +1,45 @@
package bitlove.statsd
+import com.yammer.metrics.MetricsGroup
import com.yammer.metrics.Counter
-import com.yammer.metrics.LoadMeter
+import com.yammer.metrics.Meter
import com.yammer.metrics.Timer
-import com.yammer.time.Duration
import java.util.concurrent.ConcurrentHashMap
+import java.util.concurrent.TimeUnit
import scala.collection.mutable.ConcurrentMap
import scala.collection.JavaConversions.JConcurrentMapWrapper
class Stats {
+ val metricsGroup = new MetricsGroup(this.getClass)
+
val timerMetrics: ConcurrentMap[String, Timer] =
new JConcurrentMapWrapper(new ConcurrentHashMap())
val counterMetrics: ConcurrentMap[String, Counter] =
new JConcurrentMapWrapper(new ConcurrentHashMap())
- val loadMeterMetrics: ConcurrentMap[String, LoadMeter] =
+ val loadMeterMetrics: ConcurrentMap[String, Meter] =
new JConcurrentMapWrapper(new ConcurrentHashMap())
def addTiming(name: String, timeInMilliseconds: Int): Unit = {
- val timer = timerMetrics.getOrElseUpdate(name, new Timer())
- timer += Duration.milliseconds(timeInMilliseconds)
+ val timer = timerMetrics.getOrElseUpdate(name, metricsGroup.timer(name))
+ timer.update(timeInMilliseconds, TimeUnit.MILLISECONDS)
}
def incrementCounter(name: String, delta: Long): Unit = {
- withCounter(name) { counter => counter.inc(delta) }
+ withCounter(name) { counter => counter += delta }
}
def decrementCounter(name: String, delta: Long): Unit = {
- withCounter(name) { counter => counter.dec(delta) }
+ withCounter(name) { counter => counter -= delta }
}
def markLoadMeter(name: String, count: Long): Unit = {
- val meter = loadMeterMetrics.getOrElseUpdate(name, new LoadMeter())
+ val meter = loadMeterMetrics.getOrElseUpdate(name, metricsGroup.meter(name, name))
meter.mark(count)
}
private def withCounter(name: String)(f: Counter => Unit): Unit = {
- f(counterMetrics.getOrElseUpdate(name, new Counter(0)))
+ f(counterMetrics.getOrElseUpdate(name, metricsGroup.counter(name)))
}
}
@@ -1,11 +1,11 @@
package bitlove.statsd.flushing
import com.yammer.metrics.Counter
-import com.yammer.metrics.LoadMeter
+import com.yammer.metrics.Meter
import com.yammer.metrics.Timer
trait Flusher {
def flush(name: String, timer: Timer): Unit
def flush(name: String, counter: Counter): Unit
- def flush(name: String, loadMeter: LoadMeter): Unit
+ def flush(name: String, loadMeter: Meter): Unit
}
@@ -3,7 +3,7 @@ package bitlove.statsd.flushing
import com.codahale.logula.Logging
import com.yammer.metrics.Counter
-import com.yammer.metrics.LoadMeter
+import com.yammer.metrics.Meter
import com.yammer.metrics.Timer
import ganglia.gmetric.GMetric
@@ -24,19 +24,22 @@ class GMetricFlusher(host: String, port: Int, flushInterval: Int) extends Flushe
def flush(nameString: String, timer: Timer) = {
val nameAndGroup = getNameAndGroup(nameString)
+ val percentiles = timer.percentiles(0.5, 0.75, 0.95, 0.98, 0.99, 0.999).map(_.toString)
announce(nameAndGroup, "count", timer.count.toString, GMetricType.UINT32, GMetricSlope.POSITIVE)
- announce(nameAndGroup, "max", timer.max.convert(TimeUnit.MILLISECONDS).value.toString, GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
- announce(nameAndGroup, "min", timer.min.convert(TimeUnit.MILLISECONDS).value.toString, GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
- announce(nameAndGroup, "mean", timer.mean.convert(TimeUnit.MILLISECONDS).value.toString, GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
- announce(nameAndGroup, "median", timer.median.convert(TimeUnit.MILLISECONDS).value.toString, GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
- announce(nameAndGroup, "sd", timer.standardDeviation.convert(TimeUnit.MILLISECONDS).value.toString, GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
- announce(nameAndGroup, "95%", timer.p95.convert(TimeUnit.MILLISECONDS).value.toString, GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
- announce(nameAndGroup, "99%", timer.p99.convert(TimeUnit.MILLISECONDS).value.toString, GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
- announce(nameAndGroup, "99.9%", timer.p999.convert(TimeUnit.MILLISECONDS).value.toString, GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
+ announce(nameAndGroup, "max", timer.max.toString, GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
+ announce(nameAndGroup, "min", timer.min.toString, GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
+ announce(nameAndGroup, "mean", timer.mean.toString, GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
+ announce(nameAndGroup, "median", percentiles(0), GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
+ announce(nameAndGroup, "sd", timer.stdDev.toString, GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
+ announce(nameAndGroup, "75%", percentiles(1), GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
+ announce(nameAndGroup, "95%", percentiles(2), GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
+ announce(nameAndGroup, "98%", percentiles(3), GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
+ announce(nameAndGroup, "99%", percentiles(4), GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
+ announce(nameAndGroup, "99.9%", percentiles(5), GMetricType.FLOAT, GMetricSlope.BOTH, "ms")
}
- def flush(nameString: String, meter: LoadMeter) = {
+ def flush(nameString: String, meter: Meter) = {
val nameAndGroup = getNameAndGroup(nameString)
announce(nameAndGroup, "one", meter.oneMinuteRate.toString, GMetricType.UINT32, GMetricSlope.BOTH)

0 comments on commit a0c173b

Please sign in to comment.