class LogStash::Inputs::Dstat
Public Instance Methods
clear_tmpfile(file)
click to toggle source
# File lib/logstash/inputs/dstat.rb, line 70 def clear_tmpfile(file) File.open(file,"w") do |file| end end
create_dstat_events(lines)
click to toggle source
# File lib/logstash/inputs/dstat.rb, line 75 def create_dstat_events(lines) events = [] top_columns = [] second_columns = [] lines.each_with_index do |line, line_number| line.delete!("\"") next if line == "" case line_number when 0..4 when 5 top_columns = CSV.parse_line(line) top_columns.each_with_index do |value, i| if value.nil? || value == "" top_columns[i] = top_columns[i-1] end end when 6 second_columns = CSV.parse_line(line) when 7 when 8 CSV.parse_line(line).each_with_index do |value, i| stat = resolve_stat(top_columns[i], second_columns[i]) if !stat.nil? event = LogStash::Event.new("stat" => stat, "value" => value, "host" => @host) events << event end end end end events end
exec_dstat(cmd, tmpfile)
click to toggle source
# File lib/logstash/inputs/dstat.rb, line 55 def exec_dstat(cmd, tmpfile) @logger.debug? && @logger.debug("Executing dstat", :command => cmd) begin `#{cmd}` File.open(tmpfile) do |file| file.read.split("\n") end rescue Exception => e @logger.error("Exception while running dstat", :command => option, :e => e, :backtrace => e.backtrace) ensure stop end end
register()
click to toggle source
# File lib/logstash/inputs/dstat.rb, line 33 def register @logger.info("Registering Dstat Input", :type => @type, :command => @option, :interval => @interval) @host = Socket.gethostname @command = 'dstat ' + option + ' --output ' + @tmpfile + ' 1 1' end
resolve_stat(top_column, second_column)
click to toggle source
# File lib/logstash/inputs/dstat.rb, line 109 def resolve_stat(top_column, second_column) @stat_hash[top_column] ? @stat_hash[top_column][second_column] : nil end
run(queue)
click to toggle source
# File lib/logstash/inputs/dstat.rb, line 39 def run(queue) while !stop? clear_tmpfile(@tmpfile) lines = exec_dstat(@command, @tmpfile) events = create_dstat_events(lines) events.each{|event| decorate(event) queue << event } Stud.stoppable_sleep(@interval) { stop? } end end
stop()
click to toggle source
# File lib/logstash/inputs/dstat.rb, line 52 def stop end