class Fluent::Plugin::ChefAPIInput
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_chef_api.rb, line 20 def initialize super end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_chef_api.rb, line 55 def configure(conf) super if @config_file @chef_config = ChefConfig.load_file(@config_file).to_hash else @chef_config = {} end if @chef_server_url @chef_config[:endpoint] = @chef_server_url end if @node_name @chef_config[:client] = value end if @client_key @chef_config[:key] = ::File.read(@client_key) end end
emit_node_metrics(node, data)
click to toggle source
# File lib/fluent/plugin/in_chef_api.rb, line 119 def emit_node_metrics(node, data) begin router.emit("#{@tag}.run_list", Engine.now, data.merge({"value" => node.run_list.length, "node" => node.name})) if node.automatic["ohai_time"] ohai_time = node.automatic["ohai_time"].to_i router.emit("#{@tag}.ohai_time", Engine.now, data.merge({"value" => ohai_time, "node" => node.name})) router.emit("#{@tag}.behind_seconds", Engine.now, data.merge({"value" => Time.new.to_i - ohai_time, "node" => node.name})) end rescue => error log.warn("failed to fetch metrics from node: #{node.name}", error: error) end end
run()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_chef_api.rb, line 78 def run super @connection = ChefAPI::Connection.new(@chef_config.dup) timer_execute(:chef_api_input, @check_interval) do if @monitor_multi run_once(connection) else run_once_single(connection) end end end
run_once(connection)
click to toggle source
# File lib/fluent/plugin/in_chef_api.rb, line 97 def run_once(connection) data = @default_values.dup if @chef_environment nodes = connection.environments.fetch(@chef_environment).nodes else nodes = connection.nodes end router.emit("#{@tag}.nodes", Engine.now, data.merge({"value" => nodes.count})) begin nodes.instance_eval do if Hash === @collection @collection = Hash[@collection.to_a.shuffle] end end rescue => error log.warn("failed to shuffle nodes", error: error) end nodes.each do |node| emit_node_metrics(node, data) end end
run_once_single(connection)
click to toggle source
# File lib/fluent/plugin/in_chef_api.rb, line 90 def run_once_single(connection) data = @default_values.dup if node = connection.nodes.fetch(connection.client) emit_node_metrics(node, data) end end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_chef_api.rb, line 73 def start thread_create(:chef_api, &method(:run)) super end