class Fluent::TopInput

Constants

INTERVAL_MIN

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_top.rb, line 46
def configure(conf)
  super
  interval = @interval > INTERVAL_MIN ? @interval : INTERVAL_MIN
  @top_command =
    if @test_cmd then
      @test_cmd
    else
      "#{@top} -d #{interval} #{@command_line ? "-c" : ""} #{@extra_switch}"
    end
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_top.rb, line 64
def shutdown
  super
  $log.trace "Shutdown top command thread."
  @top_thread.kill if @top_thread
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_top.rb, line 57
def start
  super
  @top_thread = Thread.new do
    run_top()
  end
end

Private Instance Methods

check_ps_info(ps) click to toggle source
# File lib/fluent/plugin/in_top.rb, line 86
def check_ps_info(ps)
  # For now, all conditions are "OR"ed
  case
  when @cpu_percent && ps.cpu >= @cpu_percent
    true
  when @mem_percent && ps.mem >= @mem_percent
    true
  when @mem && ps.res >= @mem * 1024 # megabytes
    true
  else
    false
  end
end
emit_message(tag, message) click to toggle source
# File lib/fluent/plugin/in_top.rb, line 100
def emit_message(tag, message)
  time = Engine.now
  # for fluent-mixin-rewrite-tag-name
  emit_tag = tag.dup
  filter_record(emit_tag, time, message)
  router.emit(emit_tag, time, message)
end
run_top() click to toggle source
# File lib/fluent/plugin/in_top.rb, line 71
def run_top
  $log.trace "Top command thread is running: " + @top_command
                    IO.popen(@top_command, "r") {|io|
    parser = Fluent::TopInputParser.new()
                            io.each {|line|
      result, ps = parser.parse(line)
      if result && check_ps_info(ps) then
        ps.args = ps.args.join(' ')
        emit_message(@tag, ps.to_h)
      end
                            }
                    }
  $log.info "Exit top command thread. (reached EOF)"
end