class SarInput
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_sar.rb, line 10 def configure(conf) super @interval_m = @sar_option.split.size.zero? ? @interval * 60 : @interval * 60 - 1 begin `sar -V` raise Fluent::ConfigError, "sar_option contains illegal characters.(sar_option: #{@sar_option})" if /[^a-zA-Z ]+/ =~ @sar_option rescue raise Fluent::ConfigError, "sar(sysstat) is not installed." end end
shutdown()
click to toggle source
# File lib/fluent/plugin/in_sar.rb, line 26 def shutdown @thread.kill end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_sar.rb, line 21 def start super @thread = Thread.new(&method(:run)) end
Private Instance Methods
run()
click to toggle source
# File lib/fluent/plugin/in_sar.rb, line 32 def run loop do @result = Hash.new @result["hostname"] = @hostname if @hostname_output Fluent::Engine.emit(@tag, Fluent::Engine.now, @result.merge(sar_execute(@sar_option.split))) sleep @interval_m end end
sar_execute(opt_ary)
click to toggle source
# File lib/fluent/plugin/in_sar.rb, line 41 def sar_execute(opt_ary) rlt = Hash.new {| k, v | h[k] = Hash.new } rec = Hash.new th = Array.new opt_ary.each {| opt | th << Thread.new { `LANG=C sar -#{opt} 1 1 | grep -vi average | tail -n2`.split("\n").each_with_index {| a, i | rlt[i] = a.split } rlt[0][0].sub!(/[0-9]{2}\:[0-9]{2}\:[0-9]{2}/, "check_time") rec.merge!(Hash[*rlt[0].zip(rlt[1]).flatten]) } } th.each {| t | t.join } rec end