Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

expand on StatsCollector api

  • Loading branch information...
commit 8e9d5af78400ad948ee2aa1287d2a70b38469d8c 1 parent 7f8001e
@freels freels authored
View
11 querulous-core/src/main/scala/com/twitter/querulous/StatsCollector.scala
@@ -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
}
View
4 querulous-ostrich4/src/main/scala/com/twitter/querulous/OstrichStatsCollector.scala
@@ -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)
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.