Class: Fluent::Plugin::FactorInput
- Inherits:
-
Input
- Object
- Input
- Fluent::Plugin::FactorInput
- Defined in:
- lib/fluent/plugin/in_factor.rb
Instance Method Summary collapse
- #before_shutdown ⇒ Object
- #configure(conf) ⇒ Object
- #gather_factor ⇒ Object
- #hostname ⇒ Object
- #interfaces ⇒ Object
- #is_virtual ⇒ Object
- #kernel ⇒ Object
- #memory ⇒ Object
- #operatingsystem ⇒ Object
- #processors ⇒ Object
- #run ⇒ Object
- #run_periodic ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #volumes ⇒ Object
Instance Method Details
#before_shutdown ⇒ Object
66 67 68 69 |
# File 'lib/fluent/plugin/in_factor.rb', line 66 def before_shutdown super gather_factor if @run_at_shutdown end |
#configure(conf) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# 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 ⇒ Object
101 102 103 |
# File 'lib/fluent/plugin/in_factor.rb', line 101 def hostname Facter.value(:hostname) end |
#interfaces ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# 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 ⇒ Object
160 161 162 |
# File 'lib/fluent/plugin/in_factor.rb', line 160 def is_virtual Facter.value(:is_virtual) end |
#kernel ⇒ Object
113 114 115 116 117 118 |
# File 'lib/fluent/plugin/in_factor.rb', line 113 def kernel { "name" => Facter.value(:kernel), "release" => Facter.value(:kernelrelease), } end |
#memory ⇒ Object
124 125 126 127 128 |
# File 'lib/fluent/plugin/in_factor.rb', line 124 def memory { "size" => Facter.value(:memorysize_mb ) } end |
#operatingsystem ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/fluent/plugin/in_factor.rb', line 105 def { "name" => Facter.value(:operatingsystem), "version" => Facter.value(:operatingsystemrelease), "family" => Facter.value(:osfamily), } end |
#processors ⇒ Object
120 121 122 |
# File 'lib/fluent/plugin/in_factor.rb', line 120 def processors Facter.value(:processors) end |
#run ⇒ Object
77 78 79 |
# File 'lib/fluent/plugin/in_factor.rb', line 77 def run gather_factor end |
#run_periodic ⇒ Object
81 82 83 84 85 86 87 |
# 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 ⇒ Object
71 72 73 74 75 |
# File 'lib/fluent/plugin/in_factor.rb', line 71 def shutdown super @thread.terminate @thread.join end |
#start ⇒ Object
56 57 58 59 60 61 62 63 64 |
# 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 ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 |
# 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 |