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) ⇒ ChefHandlerStatsd

Returns a new instance of ChefHandlerStatsd.



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

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

Instance Method Details

#reportObject



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

def report
  tags = {
    nodeName: node.name
  }

  @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', tags: tags)
  else
    @statsd.count('chef-client.success_runs', tags: tags)
  end
end