Commit 16efc0e8 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

basic SumBucket with flush working

parent be06f172
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -11,7 +11,23 @@ case class BucketKey(key: String, mode: String, flush_timeout: String)

trait AbstractBucket {

  val flush_timeout : Long
  var next_flush : Long = 0

  def sample(value: Double) : Unit
  def flush() : Double

  def sample_and_flush(value: Double) = {
    val now = FnordMetric.now

    if (next_flush == 0)
      next_flush = now

    while (next_flush <= now) {
      flush; next_flush += flush_timeout
    }

    sample(value)
  }

}
+4 −1
Original line number Diff line number Diff line
@@ -31,7 +31,10 @@ object BucketFactory {
  }

  def create_bucket(key: BucketKey) : AbstractBucket = {
    new SumBucket
    val flush_timeout = java.lang.Double.parseDouble(key.flush_timeout).
      longValue * 1000

    new SumBucket(flush_timeout)
  }

}
+4 −0
Original line number Diff line number Diff line
@@ -119,6 +119,10 @@ object FnordMetric {
  }


  def now : Long =
    System.nanoTime / 1000000


  def log(msg: String) = {
    val now = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, Locale.FRANCE)
    println("[" + now.format(new Date()) + "] " + msg)
+5 −2
Original line number Diff line number Diff line
@@ -10,8 +10,11 @@ package com.fnordmetric.enterprise
class SampleInstruction(key: String, mode: String, flush_interval: String, value: String) extends AbstractInstruction {

  def execute : String = {
    val bucket_key = BucketKey(key, mode, flush_interval)
    val bucket = BucketFactory.find_or_create_bucket(bucket_key)
    val bucket = BucketFactory.find_or_create_bucket(
      BucketKey(key, mode, flush_interval))

    bucket.sample_and_flush(java.lang.Double.parseDouble(value))

    "OK"
  }

+5 −5
Original line number Diff line number Diff line
@@ -7,14 +7,14 @@

package com.fnordmetric.enterprise

class SumBucket extends AbstractBucket {

class SumBucket(_flush_timeout: Long) extends AbstractBucket {
  val flush_timeout = _flush_timeout
  var tmp : Double = 0

  def sample(value: Double) : Unit =
    tmp += value
  def sample(value: Double) : Unit = {
    tmp += value; println("val: " + tmp) }

  def flush : Double =
    { val res = tmp; tmp = 0; res }
    { val res = tmp; tmp = 0; println("flush: " + res); res }

}