Class: ChefHandlerStatsd

Inherits:
Chef::Handler
  • Object
show all
Defined in:
lib/chef-handler-statsd.rb

Instance Method Summary collapse

Constructor Details

#initialize(host = 'localhost', port = 8125, tags = {}) ⇒ ChefHandlerStatsd

Returns a new instance of ChefHandlerStatsd.



7
8
9
10
# File 'lib/chef-handler-statsd.rb', line 7

def initialize(host = 'localhost', port = 8125, tags = {})
  @statsd = Datadog::Statsd.new(host, port)
  @tags = tags
end

Instance Method Details

#reportObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/chef-handler-statsd.rb', line 12

def report
  tags = {
    nodeName: node.name
  }

  tags.merge!(@tags)

  @statsd.count('chef-client.total_runs', 1, tags: tags)
  @statsd.timing('chef-client.run_time', (run_status.elapsed_time * 1000), tags: tags)
  @statsd.count('chef-client.total_resources', run_status.all_resources.length, tags: tags)
  @statsd.count('chef-client.updated_resources', run_status.updated_resources.length, tags: tags)

  if run_status.failed?
    @statsd.count('chef-client.failed_runs', 1, tags: tags)
  else
    @statsd.count('chef-client.success_runs', 1, tags: tags)
  end
end