class Dogcatcher::Notifier

Sends events/notices to the Datadog API and/or a statsd collector.

Public Class Methods

new(config) click to toggle source

@param [Dogcatcher::Config] config

# File lib/dogcatcher/notifier.rb, line 5
def initialize(config)
  @config = config
end

Public Instance Methods

notify(notice) click to toggle source

Sends events/notices to the Datadog API and/or a statsd collector.

@param [Dogcatcher::Notice]

# File lib/dogcatcher/notifier.rb, line 12
def notify(notice)
  if @config.use_dogapi?
    notify_dogapi_event(notice) if @config.send_event
    notify_dogapi_metric(notice) if @config.send_metric
  end
  if @config.use_statsd?
    notify_statsd_event(notice) if @config.send_event
    notify_statsd_metric(notice) if @config.send_metric
  end
end

Private Instance Methods

dogapi_client() click to toggle source
# File lib/dogcatcher/notifier.rb, line 25
def dogapi_client
  @dogapi_client ||= Dogapi::Client.new(@config.api_key)
end
notify_dogapi_event(notice) click to toggle source

@param [Dogcatcher::Notice]

# File lib/dogcatcher/notifier.rb, line 34
def notify_dogapi_event(notice)
  event = Dogapi::Event.new(notice.message,
                            msg_title: notice.title,
                            tags: notice.tags,
                            alert_type: 'error')
  dogapi_client.emit_event(event)
end
notify_dogapi_metric(notice) click to toggle source

@param [Dogcatcher::Notice]

# File lib/dogcatcher/notifier.rb, line 43
def notify_dogapi_metric(notice)
  dogapi_client.emit_point(@config.metric_name, 1, tags: notice.tags, type: 'counter' )
end
notify_statsd_event(notice) click to toggle source

@param [Dogcatcher::Notice]

# File lib/dogcatcher/notifier.rb, line 48
def notify_statsd_event(notice)
  statsd_client.event(notice.title,
                      notice.message,
                      tags: notice.tags,
                      alert_type: 'error')
end
notify_statsd_metric(notice) click to toggle source

@param [Dogcatcher::Notice]

# File lib/dogcatcher/notifier.rb, line 56
def notify_statsd_metric(notice)
  statsd_client.count(@config.metric_name, 1, tags: notice.tags)
end
statsd_client() click to toggle source
# File lib/dogcatcher/notifier.rb, line 29
def statsd_client
  @statsd_client = Statsd.new(@config.statsd_host, @config.statsd_port)
end