in src/main/scala/com/twitter/iago/server/AutoStats.scala [115:164]
private[this] def loop(serviceName: String) {
val statsSource = statsSourceF()
val logLocally = logLocallyF()
val logIt: () => Service[Sample, Unit] =
if (logLocally) {
Logger.configure(
List(
new LoggerFactory(
node = "stats",
level = Some(Level.INFO),
useParents = false,
handlers = List(
FileHandler(
filename = localStatsLogNameF(),
rollPolicy = Policy.MaxSize(10.megabytes),
rotateCount = 6
)
)
)
)
)
toFile()
} else {
val scribeDest = "scribe=" + statsScribeF()
lg.info("the scribe destination for statistics collection is %s", scribeDest)
() =>
toScribe(Thrift.client.newIface[Scribe.FutureIface](scribeDest))
}
var startTime = System.currentTimeMillis()
val sleepInterval = 1000 * (if (logLocally) 1 else 60)
while (go) {
// sleep for an interval, correcting for drift
startTime += sleepInterval
val delta = startTime - System.currentTimeMillis()
if (delta > 0) {
// write a sample
val stats = sample(serviceName, statsSource) andThen
ignoreErrors[Sample] andThen
logIt()
stats()
Thread.sleep(delta)
}
}
}