Sha256: a08ceb884cb1088a42f53124b572370a4103d7c78d84b9d0f420fc9b7b2803ee
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
class SadfInput < Fluent::Input Fluent::Plugin.register_input('sadf', self) config_param :sar_option, :string, default: '' config_param :tag, :string, default: 'sadf_result.tag' config_param :interval, :integer, default: 5 config_param :hostname_output, :bool, default: true config_param :hostname, :string, default: Socket.gethostname def configure(conf) super @interval_m = @sar_option.split.size.zero? ? @interval * 60 : @interval * 60 - 1 begin `sar -V` rescue raise Fluent::ConfigError, "sar(sysstat) is not installed." end end def start super @thread = Thread.new(&method(:run)) end def shutdown @thread.kill end private def run loop do @result = Hash.new @result["hostname"] = @hostname if @hostname_output @result["args"] = @sar_option Fluent::Engine.emit(@tag, Fluent::Engine.now, @result.merge(sadf_execute(@sar_option))) sleep @interval_m end end def sadf_execute(opt) rec = Hash.new `LANG=C sadf -- #{opt} 1 1`.split("\n").each {| line | array = line.split("\t") if !rec.has_key?(array[3]) then rec[array[3]] = Hash.new end rec[array[3]][array[4]] = array[5] } rec end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fluent-plugin-sadf-0.0.1 | lib/fluent/plugin/in_sadf.rb |