class Bosh::Monitor::Plugins::DataDog
Constants
- NORMAL_PRIORITY
Public Instance Methods
dog_client()
click to toggle source
# File lib/bosh/monitor/plugins/datadog.rb, line 21 def dog_client return @dog_client if @dog_client client = Dogapi::Client.new(@api_key, @application_key) @dog_client = @pagerduty_service_name ? PagingDatadogClient.new(@pagerduty_service_name, client) : client end
process(event)
click to toggle source
# File lib/bosh/monitor/plugins/datadog.rb, line 27 def process(event) case event when Bosh::Monitor::Events::Heartbeat if event.node_id EM.defer { process_heartbeat(event) } end when Bosh::Monitor::Events::Alert EM.defer { process_alert(event) } else #ignore end end
run()
click to toggle source
# File lib/bosh/monitor/plugins/datadog.rb, line 13 def run @api_key = options["api_key"] @application_key = options["application_key"] @pagerduty_service_name = options["pagerduty_service_name"] logger.info("DataDog plugin is running...") end
validate_options()
click to toggle source
# File lib/bosh/monitor/plugins/datadog.rb, line 9 def validate_options !!(options.kind_of?(Hash) && options["api_key"] && options["application_key"]) end
Private Instance Methods
normal_priority?(severity)
click to toggle source
# File lib/bosh/monitor/plugins/datadog.rb, line 88 def normal_priority?(severity) NORMAL_PRIORITY.include?(severity) end
process_alert(alert)
click to toggle source
# File lib/bosh/monitor/plugins/datadog.rb, line 63 def process_alert(alert) msg, title, source, timestamp = alert.to_hash.values_at(:summary, :title, :source, :created_at) # DataDog only supports "low" and "normal" priority begin priority = normal_priority?(alert.severity) ? "normal" : "low" dog_client.emit_event( Dogapi::Event.new(msg, msg_title: title, date_happened: timestamp, tags: ["source:#{source}"], priority: priority ) ) rescue Timeout::Error => e logger.warn('Could not emit event to Datadog, request timed out.') rescue => e logger.warn("Could not emit event to Datadog: #{e.inspect}") end end
process_heartbeat(heartbeat)
click to toggle source
# File lib/bosh/monitor/plugins/datadog.rb, line 42 def process_heartbeat(heartbeat) tags = %W[ job:#{heartbeat.job} index:#{heartbeat.index} id:#{heartbeat.node_id} deployment:#{heartbeat.deployment} agent:#{heartbeat.agent_id} ] heartbeat.metrics.each do |metric| begin point = [Time.at(metric.timestamp), metric.value] dog_client.emit_points("bosh.healthmonitor.#{metric.name}", [point], tags: tags) rescue Timeout::Error => e logger.warn('Could not emit points to Datadog, request timed out.') rescue => e logger.info("Could not emit points to Datadog: #{e.inspect}") end end end