Module: Sidekiq::Datadog::Monitor

Defined in:
lib/sidekiq/datadog/monitor.rb,
lib/sidekiq/datadog/monitor/version.rb,
lib/sidekiq/datadog/monitor/tag_builder.rb,
lib/sidekiq/datadog/monitor/metrics_sender.rb,
lib/sidekiq/datadog/monitor/heartbeat_patch.rb

Defined Under Namespace

Modules: HeartbeatPatch Classes: Error, MetricsSender, TagBuilder

Constant Summary collapse

VERSION =
'1.1.1'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.agent_hostObject

Returns the value of attribute agent_host.



13
14
15
# File 'lib/sidekiq/datadog/monitor.rb', line 13

def agent_host
  @agent_host
end

.agent_portObject

Returns the value of attribute agent_port.



13
14
15
# File 'lib/sidekiq/datadog/monitor.rb', line 13

def agent_port
  @agent_port
end

.senderObject

Returns the value of attribute sender.



13
14
15
# File 'lib/sidekiq/datadog/monitor.rb', line 13

def sender
  @sender
end

.statsdObject

Returns the value of attribute statsd.



13
14
15
# File 'lib/sidekiq/datadog/monitor.rb', line 13

def statsd
  @statsd
end

.tags_builderObject

Returns the value of attribute tags_builder.



13
14
15
# File 'lib/sidekiq/datadog/monitor.rb', line 13

def tags_builder
  @tags_builder
end

Class Method Details

.configure!(options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/sidekiq/datadog/monitor.rb', line 15

def configure!(options)
  raise Sidekiq::Datadog::Monitor::Error, "Can't configure two times" if configured?

  @agent_host, @agent_port = options.fetch_values(:agent_host, :agent_port)
  @tags_builder = Sidekiq::Datadog::Monitor::TagBuilder.new(options[:tags] || [])

  add_sidekiq_listeners
rescue KeyError => e
  raise Sidekiq::Datadog::Monitor::Error, "Required param is missing: #{e.message}"
end

.configured?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/sidekiq/datadog/monitor.rb', line 26

def configured?
  agent_host && agent_port
end

.initialize!Object



30
31
32
33
# File 'lib/sidekiq/datadog/monitor.rb', line 30

def initialize!
  @statsd = ::Datadog::Statsd.new(agent_host, agent_port)
  @sender = Sidekiq::Datadog::Monitor::MetricsSender.new(statsd, tags_builder)
end

.send_metricsObject



35
36
37
38
39
40
41
42
# File 'lib/sidekiq/datadog/monitor.rb', line 35

def send_metrics
  sender&.send_metrics
rescue ArgumentError => e
  # Ignore this error. Sometimes sender hasn't yet started when we send metrics for the first time on boot
  return if sender && e.message == 'Start sender first'

  raise
end

.shutdown!Object



44
45
46
47
# File 'lib/sidekiq/datadog/monitor.rb', line 44

def shutdown!
  @sender = nil # Remove sender first so beat event after shutdown does not raising error
  statsd.close
end