Class: Ruby::Reporters::Datadog

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/reporters/datadog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Datadog



8
9
10
11
12
13
14
15
16
17
# File 'lib/ruby/reporters/datadog.rb', line 8

def initialize(opts={})
  statsd_host                 = opts[:statsd_host] || "localhost"
  statsd_port                 = opts[:statsd_port] || 8125
  namespace                   = opts[:statsd_prefix] || nil
  
  @default_http_tags          = ['type:http']
  @response_time_metric_name  = 'response_time_ms'
  
  @statsd = opts[:statsd] || ::Datadog::Statsd.new(statsd_host, statsd_port, namespace: namespace)
end

Instance Attribute Details

#default_http_tagsObject (readonly)

Returns the value of attribute default_http_tags.



6
7
8
# File 'lib/ruby/reporters/datadog.rb', line 6

def default_http_tags
  @default_http_tags
end

#response_time_metric_nameObject (readonly)

Returns the value of attribute response_time_metric_name.



6
7
8
# File 'lib/ruby/reporters/datadog.rb', line 6

def response_time_metric_name
  @response_time_metric_name
end

#statsdObject (readonly)

Returns the value of attribute statsd.



6
7
8
# File 'lib/ruby/reporters/datadog.rb', line 6

def statsd
  @statsd
end

Instance Method Details

#gauge(metric_name, value, tags) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/ruby/reporters/datadog.rb', line 29

def gauge(metric_name, value, tags)
  statsd.gauge(
    metric_name,
    value,
    tags: tags
  )
end

#histogram(metric_name, value, tags) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/ruby/reporters/datadog.rb', line 44

def histogram(metric_name, value, tags)
  statsd.histogram(
    metric_name,
    value,
    tags:tags
  )
end

#increment(metric_name, tags) ⇒ Object



37
38
39
40
41
42
# File 'lib/ruby/reporters/datadog.rb', line 37

def increment(metric_name, tags)
  statsd.increment(
    metric_name,
    tags: tags
  )
end

#response_time_ms(path, method, status, value) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/ruby/reporters/datadog.rb', line 19

def response_time_ms(path, method, status, value)
  tags = [
    "route:#{method.upcase} #{path}",
    "status:#{status}",
    "error:#{from_status_to_error(status)}"
  ]

  histogram(response_time_metric_name, value, default_http_tags | tags)
end