class SadfInput

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_sadf.rb, line 12
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
shutdown() click to toggle source
# File lib/fluent/plugin/in_sadf.rb, line 27
def shutdown
    @thread.kill
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_sadf.rb, line 22
def start
    super
    @thread = Thread.new(&method(:run))
end

Private Instance Methods

run() click to toggle source
# File lib/fluent/plugin/in_sadf.rb, line 33
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
sadf_execute(opt) click to toggle source
# File lib/fluent/plugin/in_sadf.rb, line 43
def sadf_execute(opt)
    rec = Hash.new

    Tempfile.open('sar') {|tmpfile|
        `LANG=C sar -o #{tmpfile.path} 1 1`
        `LANG=C sadf -- #{opt} 1 1 #{tmpfile.path}`.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