Commit 14b54b95 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

basic implementation of Metric#values_in

parent 879c2406
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ class Metric(key: MetricKey) {
    var rbuf_pos = 0

    // search our rbuf snapshot backwards
    while (rbuf_pos > 0 && rbuf_pos < rbuf_snap.size) {
    while (rbuf_pos >= 0 && rbuf_pos < rbuf_snap.size) {
      val cur = rbuf_snap(rbuf_pos)

      // since the snapshot is not atomic, we need to check if we hit
@@ -105,7 +105,7 @@ class Metric(key: MetricKey) {
        rbuf_pos = -1

      // continues only if we didn't hit the buffer wrap
      if (rbuf_pos > 0) {
      if (rbuf_pos >= 0) {

        // check if we found the start of the range yet
        if (cur._1 <= time0 && ((cur._1 >= time1) || time1 == 0)) {
@@ -122,6 +122,9 @@ class Metric(key: MetricKey) {

        }
      }

      if (rbuf_pos >= 0)
        rbuf_pos += 1
    }

    // exit if we have already seen the whole time range and don't need to
+7 −2
Original line number Diff line number Diff line
@@ -10,8 +10,13 @@ package com.fnordmetric.enterprise
class ValueAtInstruction(key: MetricKey, time: Long) extends AbstractInstruction {

  def execute : String = {
    MetricFactory.get_metric(key)
    "OKFNORD"
    val metric = MetricFactory.get_metric(key)
    val value = metric.value_at(time * 1000).getOrElse(null)

    if (value == null)
      "null"
    else
      value.toString
  }

}
+4 −2
Original line number Diff line number Diff line
@@ -10,8 +10,10 @@ package com.fnordmetric.enterprise
class ValuesInInstruction(key: MetricKey, time0: Long, time1: Long) extends AbstractInstruction {

  def execute : String = {
    MetricFactory.get_metric(key)
    "OKIDOKI"
    val metric = MetricFactory.get_metric(key)
    val values = metric.values_in(time1 * 1000, time0 * 1000)

    values.toString
  }

}