Class: ChefInfluxDB

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = defaults) ⇒ ChefInfluxDB

Returns a new instance of ChefInfluxDB.



30
31
32
33
34
35
36
37
38
# File 'lib/chef-handler-influxdb.rb', line 30

def initialize(options = defaults)
  @database = options[:database]
  @series = options[:series]
  @host = options[:host]
  @port = options[:port]
  @user = options[:user]
  @pass = options[:pass]
  @data = options[:data]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



28
29
30
# File 'lib/chef-handler-influxdb.rb', line 28

def data
  @data
end

#databaseObject (readonly)

Returns the value of attribute database.



28
29
30
# File 'lib/chef-handler-influxdb.rb', line 28

def database
  @database
end

#hostObject (readonly)

Returns the value of attribute host.



28
29
30
# File 'lib/chef-handler-influxdb.rb', line 28

def host
  @host
end

#passObject (readonly)

Returns the value of attribute pass.



28
29
30
# File 'lib/chef-handler-influxdb.rb', line 28

def pass
  @pass
end

#portObject (readonly)

Returns the value of attribute port.



28
29
30
# File 'lib/chef-handler-influxdb.rb', line 28

def port
  @port
end

#seriesObject (readonly)

Returns the value of attribute series.



28
29
30
# File 'lib/chef-handler-influxdb.rb', line 28

def series
  @series
end

#userObject (readonly)

Returns the value of attribute user.



28
29
30
# File 'lib/chef-handler-influxdb.rb', line 28

def user
  @user
end

Instance Method Details

#clientObject



51
52
53
54
55
56
57
58
59
# File 'lib/chef-handler-influxdb.rb', line 51

def client
  return InfluxDB::Client.new(
    @database,
    :host => @host,
    :port => @port,
    :username => @user,
    :password => @pass
  )
end

#defaultsObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/chef-handler-influxdb.rb', line 40

def defaults
  return {
    :user => 'root',
    :pass => 'root',
    :host => 'localhost',
    :port => 8086,
    :database => nil,
    :series => nil
  }
end

#generate_dataObject



61
62
63
64
65
66
67
68
69
# File 'lib/chef-handler-influxdb.rb', line 61

def generate_data
  return {
    :host => node.name,
    :status => run_status.success? ? 1 : 0,
    :resources_updated => run_status.updated_resources.length,
    :elapsed_time => run_status.elapsed_time,
    :end_time => Time.now.to_s
  }.merge(@data || {})
end

#reportObject



71
72
73
74
# File 'lib/chef-handler-influxdb.rb', line 71

def report
  Chef::Log.info 'Exporting Chef run data to InfluxDB'
  client.write_point(@series, generate_data)
end