Commit 1cff0217 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

toplist gauge wip

parent c1bdc492
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -61,10 +61,10 @@ module FnordMetric::GaugeCalculations
  end

  def field_values_at(time, opts={}, &block)
    opts[:max_fields] ||= 50
    opts[:limit] ||= (opts[:max_fields] || 50)
    sync_redis.zrevrange(
      tick_key(time), 
      0, opts[:max_fields]-1, 
      tick_key(time, opts[:append]), 
      0, opts[:limit]-1, 
      :withscores => true
    ).in_groups_of(2).map do |key, val|
      [key, calculate_value(val, time, opts, block)]
+13 −2
Original line number Diff line number Diff line
@@ -2,9 +2,17 @@ class FnordMetric::ToplistGauge < FnordMetric::Gauge

  def render(namespace, event)
    interval = parse_interval(event["interval"])
    colors = ["#2F635E", "#606B36", "#727070", "#936953", "#CD645A", "#FACE4F", "#42436B"]

    #res = @opts[:redis].zrevrangebyscore(rkey, "+inf", 0, :limit => [0, @opts[:show_top_n]]) 
    #@toplist = FnordMetric::Toplist.new

    ticks_in(interval).each do |_tick|
      puts field_values_at(_tick, 
        :limit => top_k, 
        :append => :toplist
      ).inspect
    end    

    @toplist = {}

    render_page(:toplist_gauge)
  end
@@ -21,8 +29,11 @@ class FnordMetric::ToplistGauge < FnordMetric::Gauge
private

  def observe(ctx, item)
    puts "YAY"

    at = ctx.send(:time)
    ctx.redis_exec :zincrby, tick_key(at, :toplist), 1, item
    ctx.redis_exec :incrby, tick_key(at, :total), 1
    ctx.redis_exec :zremrangebyrank, tick_key(at, :toplist), 0, -top_k
  end

+3 −3
Original line number Diff line number Diff line
@@ -18,10 +18,10 @@
    .headbar
      %h2 Top 50 #{key_nouns.last}
    .ui_toplist
      -50.times do
      - @toplist.each do |item, score|
        .toplist_item
          .title keyword
          .value 36
          .title= item
          .value= score
          .percent 73.5%