Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16cdec0
commit a0c173b
Showing
4 changed files
with
28 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters