class NewRelicPing::Configuration

Attributes

monitors[RW]

Public Class Methods

new(data={}) click to toggle source
# File lib/new_relic_ping/configuration.rb, line 6
def initialize(data={})
  @data = {}
  @monitors = {}
  update!(data)
  load_default_monitors
end

Public Instance Methods

[](key) click to toggle source
# File lib/new_relic_ping/configuration.rb, line 19
def [](key)
  @data[key.to_sym]
end
[]=(key, value) click to toggle source
# File lib/new_relic_ping/configuration.rb, line 23
def []=(key, value)
  @data[key.to_sym] = value
end
load_default_monitors() click to toggle source
# File lib/new_relic_ping/configuration.rb, line 39
def load_default_monitors
  if defined?(ActiveRecord::Base)
    monitor('database') do
      ActiveRecord::Base.connection.select_values("select 1") == [1]
    end
  end
end
method_missing(sym, *args) click to toggle source
# File lib/new_relic_ping/configuration.rb, line 27
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/new_relic_ping/configuration.rb, line 35
def monitor(label, &block)
  @monitors[label.to_s] = block
end
status_check() click to toggle source
# File lib/new_relic_ping/configuration.rb, line 47
def status_check
  responses = {}
  begin
    @monitors.each do |label, mon|
      return_value = nil
      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/new_relic_ping/configuration.rb, line 13
def update!(data)
  data.each do |key, value|
    self[key] = value
  end
end