class Fluent::Plugin::FactorInput
Public Instance Methods
before_shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_factor.rb, line 66 def before_shutdown super gather_factor if @run_at_shutdown end
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_factor.rb, line 25 def configure(conf) super if !@run_interval && @run_at_start raise ConfigError, "'run_at_start' option needs 'run_interval' option" end factor_keys = [ "hostname", "operatingsystem", "kernel", "processors", "memory", "volumes", "interfaces", "is_virtual", ] @factors = @factors.to_h if @factors.empty? factor_keys.each do |key| @factors[key] = true end end if @factors.select { |k,v| v == true }.empty? raise ConfigError, "one or more factor are required" end end
gather_factor()
click to toggle source
# File lib/fluent/plugin/in_factor.rb, line 89 def gather_factor begin record = {} @factors.each do |factor, enabled| record[factor] = send(factor) if enabled end router.emit(@tag, Fluent::EventTime.now, record) rescue => e router.emit_error_event(@tag, Fluent::EventTime.now, record, e) end end
hostname()
click to toggle source
# File lib/fluent/plugin/in_factor.rb, line 101 def hostname Facter.value(:hostname) end
interfaces()
click to toggle source
# File lib/fluent/plugin/in_factor.rb, line 143 def interfaces interfaces = [] interface_names = Facter.value(:interfaces).split(/,/) if interface_names interface_names.each do |if_name| next if if_name == "lo" interfaces.push({ "name" => if_name, "ipaddress" => Facter.value("ipaddress_#{if_name}"), "netmask" => Facter.value("netmask_#{if_name}"), "macaddress" => Facter.value("macaddress_#{if_name}"), }) end end interfaces end
is_virtual()
click to toggle source
# File lib/fluent/plugin/in_factor.rb, line 160 def is_virtual Facter.value(:is_virtual) end
kernel()
click to toggle source
# File lib/fluent/plugin/in_factor.rb, line 113 def kernel { "name" => Facter.value(:kernel), "release" => Facter.value(:kernelrelease), } end
memory()
click to toggle source
# File lib/fluent/plugin/in_factor.rb, line 124 def memory { "size" => Facter.value(:memorysize_mb ) } end
operatingsystem()
click to toggle source
# File lib/fluent/plugin/in_factor.rb, line 105 def operatingsystem { "name" => Facter.value(:operatingsystem), "version" => Facter.value(:operatingsystemrelease), "family" => Facter.value(:osfamily), } end
processors()
click to toggle source
# File lib/fluent/plugin/in_factor.rb, line 120 def processors Facter.value(:processors) end
run()
click to toggle source
# File lib/fluent/plugin/in_factor.rb, line 77 def run gather_factor end
run_periodic()
click to toggle source
# File lib/fluent/plugin/in_factor.rb, line 81 def run_periodic gather_factor if @run_at_start while true sleep @run_interval gather_factor end end
shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_factor.rb, line 71 def shutdown super @thread.terminate @thread.join end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_factor.rb, line 56 def start super if @run_interval @finished = false @thread = Thread.new(&method(:run_periodic)) else @thread = Thread.new(&method(:run)) end end
volumes()
click to toggle source
# File lib/fluent/plugin/in_factor.rb, line 130 def volumes volumes = [] blockdevice_names = Facter.value(:blockdevices).split(/,/) blockdevice_names.each do |device_name| next if device_name !~ /(hd.*|sd.*|md.*)/ volumes.push({ "name" => device_name, "size" => Facter.value("blockdevice_#{device_name}_size") / 1024 / 1024 / 1024, }) end volumes end