Commit f5a2ee8a authored by Paul Asmuth's avatar Paul Asmuth
Browse files

Merge branch 'dev' of falbala.23loc.com:fnordmetric into dev

parents f05a8d2a 2b5a3cb9
Loading
Loading
Loading
Loading
+1 −13
Original line number Diff line number Diff line
@@ -51,19 +51,7 @@ module FnordMetric
  end

  def self.default_options(opts = {})
    {
      :redis_url => "redis://localhost:6379",
      :redis_prefix => "fnordmetric",
      :inbound_stream => ["0.0.0.0", "1337"],
      :inbound_protocol => :tcp,
      :web_interface => ["0.0.0.0", "4242"],
      :web_interface_server => "thin",
      :start_worker => true,
      :print_stats => 3,
      :event_queue_ttl => 120,
      :event_data_ttl => 3600*24*30,
      :session_data_ttl => 3600*24*30
    }.merge(opts)
    FnordMetric::DEFAULT_OPTIONS.merge(opts)
  end

  def self.log(msg)
+15 −49
Original line number Diff line number Diff line
FnordMetric::COLORS = ["#4572a7", "#aa4643", "#89a54e", "#80699b", "#3d96ae", "#db843d"].reverse

FnordMetric::DEFAULT_PROC = lambda{ |arg| }

FnordMetric::TICKS = lambda{ |tick, span| [tick, 60, 300, 1200, 3600, 86400]
  .select{ |t| (t >= tick) && ((span/t) > 5) }
  .uniq }

FnordMetric::DEFAULT_PROC = lambda{ |arg| }

FnordMetric::ZERO_CONFIG_TYPES = [:_incr, :_decr, :_avg, :_min, :_max, :_set]

FnordMetric::ZERO_CONFIG_HANDLER = proc {
  if data[:gauge]
    gauge_key = data[:gauge].to_sym
  else
    FnordMetric.error("missing key for zero config event: gauge")
    next
  end

  unless data[:flush_interval]
    FnordMetric.error("missing key for zero config event: flush_interval")
    next
  end

  unless data[:value]
    FnordMetric.error("missing key for zero config event: value")
    next
  end

  gauge = if namespace.gauges.has_key?(gauge_key)
    namespace.gauges[gauge_key]
  else
    namespace.opt_gauge(gauge_key,
      :tick => data[:flush_interval].to_i,
      :average => (type == :_avg),
      :zero_config => true)
  end

  case type

    when :_set
      set_value gauge, data[:value]

    when :_incr
      incr_tick gauge, data[:value]

    when :_decr
      FnordMetric.error("_decr is not yet implemented")

    when :_avg
      incr_avg gauge, data[:value]

    when :_min, :_max
      FnordMetric.error("_min/_max is not yet implemented")

  end
FnordMetric::DEFAULT_OPTIONS = {
  :redis_url => "redis://localhost:6379",
  :redis_prefix => "fnordmetric",
  :inbound_stream => nil,
  :inbound_protocol => nil,
  :web_interface => ["0.0.0.0", "4242"],
  :web_interface_server => "thin",
  :start_worker => true,
  :print_stats => 3,
  :event_queue_ttl => 120,
  :event_data_ttl => 3600*24*30,
  :session_data_ttl => 3600*24*30,
  :default_flush_interval => 10
}
+2 −1
Original line number Diff line number Diff line
@@ -11,7 +11,8 @@ class FnordMetric::Gauge
  end

  def tick
    (@opts[:tick] || @opts[:resolution] || 3600).to_i
    (@opts[:tick] || @opts[:resolution] || @opts[:flush_interval] ||
      FnordMetric.options[:default_flush_interval]).to_i
  end

  def retention
+12 −16
Original line number Diff line number Diff line
@@ -11,12 +11,14 @@ class FnordMetric::Namespace
    @gauges = Hash.new
    @dashboards = Hash.new
    @handlers = Hash.new.with_indifferent_access
    @flags = Hash.new
    @title = key
    @active_users_available = true
    @gauge_explorer_available = true
    @opts = opts
    @key = key

    @flags = {
      :hide_active_users => (FnordMetric.options[:enable_active_users] == false),
      :hide_gauge_explorer => (FnordMetric.options[:enable_gauge_explorer] == false)
    }
  end

  def ready!(redis, sync_redis = nil)
@@ -27,7 +29,7 @@ class FnordMetric::Namespace
  end

  def announce(event)
    if active_users_available
    if !@flags[:hide_active_users]
      announce_to_timeline(event)
      announce_to_typelist(event)
    end
@@ -36,8 +38,8 @@ class FnordMetric::Namespace
      event[:_session_key] = announce_to_session(event).session_key 
    end

    if FnordMetric::ZERO_CONFIG_TYPES.include?(event[:_type].to_sym)
      ctx = FnordMetric::Context.new(opts, FnordMetric::ZERO_CONFIG_HANDLER)
    if FnordMetric::ZeroConfigGauge::TYPES.include?(event[:_type].to_sym)
      ctx = FnordMetric::Context.new(opts, FnordMetric::ZeroConfigGauge::Handler)
      ctx.call(event, @redis, self)
      return self
    end
@@ -88,14 +90,6 @@ class FnordMetric::Namespace
    @title
  end

  def active_users_available
    !!@active_users_available
  end

  def gauge_explorer_available
    !!@active_users_available
  end

  def dashboards(name=nil, opts = {})
    return @dashboards unless name
    dash = FnordMetric::Dashboard.new(opts.merge(:title => name))
@@ -166,7 +160,7 @@ class FnordMetric::Namespace

  def build_widget(opts)
    _gauges = [opts[:gauges]].flatten.map do |g|
      @gauges[g] || ZeroConfigGauge.new(g, self)
      @gauges[g] || FnordMetric::ZeroConfigGauge.new(g, self)
    end
    widget_klass = "FnordMetric::#{opts.fetch(:type).to_s.capitalize}Widget"
    widget_klass.constantize.new(opts.merge(:gauges => _gauges))
@@ -180,7 +174,9 @@ class FnordMetric::Namespace
  def load_gauges
    gaugelist_key = key_prefix("zero-config-gauges")
    sync_redis.hgetall(gaugelist_key).each do |gauge_key, gauge_opts|
      opt_gauge(gauge_key.to_sym, JSON.parse(gauge_opts).symbolize_keys)
      gopts = JSON.parse(gauge_opts).symbolize_keys
      gopts.delete(:zero_config)
      opt_gauge(gauge_key.to_sym, gopts)
    end
  end

+4 −0
Original line number Diff line number Diff line
@@ -14,6 +14,10 @@ class FnordMetric::NumbersWidget < FnordMetric::Widget
  end

  def self.execute_values_for(gauge, event)
    unless gauge
      return { "error" => "gauge not found..." }
    end

    _t = Time.now.to_i

    if at = event["at"]
Loading