Permalink
Browse files

expand on StatsCollector api

  • Loading branch information...
1 parent 7f8001e commit 8e9d5af78400ad948ee2aa1287d2a70b38469d8c @freels freels committed Nov 29, 2011
@@ -1,12 +1,23 @@
package com.twitter.querulous
+import com.twitter.util.{Time, Future}
+
trait StatsCollector {
def incr(name: String, count: Int)
def time[A](name: String)(f: => A): A
def addGauge(name: String)(gauge: => Double) {}
+ def addMetric(name: String, value: Int) {}
+
+ def timeFutureMillis[T](name: String)(f: Future[T]) = {
+ val start = Time.now
+ f respond { _ =>
+ addMetric(name +"_msec", start.untilNow.inMilliseconds.toInt)
+ }
+ }
}
object NullStatsCollector extends StatsCollector {
def incr(name: String, count: Int) {}
def time[A](name: String)(f: => A): A = f
+ override def timeFutureMillis[T](name: String)(f: Future[T]) = f
}
@@ -15,4 +15,8 @@ class OstrichStatsCollector(stats: StatsProvider) extends StatsCollector {
override def addGauge(name: String)(gauge: => Double) {
stats.addGauge(name)(gauge)
}
+
+ override def addMetric(name: String, value: Int) {
+ stats.addMetric(name, value)
+ }
}

0 comments on commit 8e9d5af

Please sign in to comment.