Module: FnordMetric

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

Defined Under Namespace

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

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.default_options(opts = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fnordmetric.rb', line 53

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)
end

.error(msg) ⇒ Object



73
74
75
# File 'lib/fnordmetric.rb', line 73

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

.error!(msg) ⇒ Object



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

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

.log(msg) ⇒ Object



69
70
71
# File 'lib/fnordmetric.rb', line 69

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



82
83
84
85
86
87
88
# File 'lib/fnordmetric.rb', line 82

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

.server_configuration=(configuration) ⇒ Object



108
109
110
111
# File 'lib/fnordmetric.rb', line 108

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

.shutdown(fnord = nil) ⇒ Object



90
91
92
93
# File 'lib/fnordmetric.rb', line 90

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

.standaloneObject



113
114
115
116
117
# File 'lib/fnordmetric.rb', line 113

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

.start_emObject



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/fnordmetric.rb', line 95

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