Module: FnordMetric

Defined in:
lib/fnordmetric.rb,
lib/fnordmetric/version.rb,
lib/fnordmetric/web/event.rb

Defined Under Namespace

Modules: AppHelpers, Enterprise, GaugeCalculations, GaugeModifiers, GaugeRendering, GaugeValidations Classes: AMQPAcceptor, API, Acceptor, App, BarsWidget, Cache, Context, Dashboard, DistributionGauge, Event, FyrehoseAcceptor, Gauge, Histogram, HtmlWidget, Logger, Namespace, NumbersWidget, PieWidget, Reactor, STOMPAcceptor, Session, TCPAcceptor, TimelineWidget, Timeseries, TimeseriesGauge, TimeseriesWidget, Toplist, ToplistGauge, ToplistWidget, UDPAcceptor, UDPClient, Util, Web, WebSocket, Widget, Worker, ZeroConfigGauge

Constant Summary collapse

VERSION =
"1.2.7"
COLORS =
["#4572a7", "#aa4643", "#89a54e", "#80699b", "#3d96ae", "#db843d"].reverse
DEFAULT_PROC =
lambda{ |arg| }
TICKS =
lambda{ |tick, span| [tick, 60, 300, 1200, 3600, 86400]
.select{ |t| (t >= tick) && ((span/t) > 5) }
.uniq }
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
}
@@options =
nil
@@pool =
[]
@@namespaces =
{}

Class Method Summary collapse

Class Method Details

.default_options(opts = {}) ⇒ Object



53
54
55
# File 'lib/fnordmetric.rb', line 53

def self.default_options(opts = {})
  FnordMetric::DEFAULT_OPTIONS.merge(opts)
end

.error(msg) ⇒ Object



61
62
63
# File 'lib/fnordmetric.rb', line 61

def self.error(msg)
  log "[ERROR] #{msg}"; nil
end

.error!(msg) ⇒ Object



65
66
67
68
# File 'lib/fnordmetric.rb', line 65

def self.error!(msg)
  raise msg if ENV['FNORDMETRIC_ENV'] == 'test'
  puts(msg); exit!
end

.log(msg) ⇒ Object



57
58
59
# File 'lib/fnordmetric.rb', line 57

def self.log(msg)
  puts "[#{Time.now.strftime("%y-%m-%d %H:%M:%S")}] #{msg}"
end

.mk_redisObject



49
50
51
# File 'lib/fnordmetric.rb', line 49

def self.mk_redis
  Redis.new(:url => options[:redis_url])
end

.namespace(key = nil, &block) ⇒ Object



23
24
25
# File 'lib/fnordmetric.rb', line 23

def self.namespace(key=nil, &block)
  @@namespaces[key] = block
end

.namespacesObject



27
28
29
30
31
32
33
34
35
# File 'lib/fnordmetric.rb', line 27

def self.namespaces
  {}.tap do |_namespaces|
    @@namespaces.each do |key, block|
      _namespaces[key] = FnordMetric::Namespace.new(key, options.clone)
      _namespaces[key].instance_eval(&block)
      _namespaces[key].instance_eval(&FnordMetric::DEFAULT_PROC)
    end
  end
end

.options(opts = {}) ⇒ Object



37
38
39
# File 'lib/fnordmetric.rb', line 37

def self.options(opts = {})
  default_options(@@options || {}).merge(opts)
end

.options=(opts) ⇒ Object



41
42
43
# File 'lib/fnordmetric.rb', line 41

def self.options=(opts)
  @@options = opts
end

.register(obj) ⇒ Object



45
46
47
# File 'lib/fnordmetric.rb', line 45

def self.register(obj)
  @@pool.push(obj)
end

.runObject



70
71
72
73
74
75
76
# File 'lib/fnordmetric.rb', line 70

def self.run
  start_em
rescue Exception => e
  raise e
  log "!!! eventmachine died, restarting... #{e.message}"
  sleep(1); run
end

.server_configuration=(configuration) ⇒ Object



96
97
98
99
# File 'lib/fnordmetric.rb', line 96

def self.server_configuration=(configuration)
  puts "DEPRECATION WARNING - FIXPAUL"
  self.options=(configuration)
end

.shutdown(fnord = nil) ⇒ Object



78
79
80
81
# File 'lib/fnordmetric.rb', line 78

def self.shutdown(fnord=nil)
  log "shutting down, byebye"
  EM.stop
end

.standaloneObject



101
102
103
104
105
# File 'lib/fnordmetric.rb', line 101

def self.standalone
  puts "DEPRECATION WARNING - FIXPAUL"
  require "fnordmetric/standalone"
  start_em
end

.start_emObject



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fnordmetric.rb', line 83

def self.start_em
  EM.run do

    trap("TERM", &method(:shutdown))
    trap("INT",  &method(:shutdown))

    EM.next_tick do
      (@@pool || []).map(&:initialized)
    end

  end
end