class HeartbeatRails::Configuration
Constants
- DEFAULT_MOUNTPOINT
Default mountpoint for engine
Attributes
monitors[RW]
mountpoint[R]
used in railtie to read where to mount the engine
Public Class Methods
new(data={})
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 13 def initialize(data={}) @data = {} @monitors = {} @mountpoint = DEFAULT_MOUNTPOINT @mount_mode = :append update!(data) load_default_monitors end
Public Instance Methods
[](key)
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 28 def [](key) @data[key.to_sym] end
[]=(key, value)
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 32 def []=(key, value) @data[key.to_sym] = value end
append_route!()
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 61 def append_route! @mount_mode = :append end
automount?()
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 53 def automount? !!@mount_mode end
dont_mount!()
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 69 def dont_mount! @mount_mode = nil end
load_default_monitors()
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 73 def load_default_monitors if defined?(ActiveRecord::Base) monitor('database') do # Delegate activeness check to actual AR implementation # in MySQL it would call mysql.ping in postgres it fallback to SELECT 1 ActiveRecord::Base.connection.active? end end end
method_missing(sym, *args)
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 36 def method_missing(sym, *args) if sym.to_s =~ /(.+)=$/ self[$1] = args.first else self[sym] end end
monitor(label, &block)
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 44 def monitor(label, &block) @monitors[label.to_s] = block end
mount_at(mountpoint)
click to toggle source
Configure where the engine should be mounted
# File lib/heartbeat_rails/configuration.rb, line 49 def mount_at(mountpoint) @mountpoint = mountpoint end
prepend_route!()
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 65 def prepend_route! @mount_mode = :prepend end
route_method()
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 57 def route_method @mount_mode end
status_check()
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 83 def status_check responses = {} begin @monitors.each do |label, mon| time = ::Benchmark.realtime do responses["#{label}_response"] = (mon.call).to_s end responses["#{label}_time"] = "#{time.inspect} seconds" end return :ok, responses rescue => e responses['error_message'] = e.message return :error, responses end end
update!(data)
click to toggle source
# File lib/heartbeat_rails/configuration.rb, line 22 def update!(data) data.each do |key, value| self[key] = value end end