class Fluent::FreeInput

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_free.rb, line 10
def configure(conf)
  super
  if @interval
    @tick = interval.to_i
  else
    @tick = 10
  end

  @option = case @unit
            when 'byte' then '-b'
            when 'kilo' then '-k'
            when 'mega' then '-m'
            when 'giga' then '-g'
            else
              raise RuntimeError, "@unit must be one of byte/kilo/mega/giga"
            end
end
run() click to toggle source
# File lib/fluent/plugin/in_free.rb, line 38
def run
  loop do
    Fluent::Engine.emit(@tag, Fluent::Engine.now, get_free_info)
    sleep @tick
  end
end
shutdown() click to toggle source
# File lib/fluent/plugin/in_free.rb, line 33
def shutdown
  @thread.terminate
  @thread.join
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_free.rb, line 28
def start
  super
  @thread = Thread.new(&method(:run))
end

Private Instance Methods

get_free_info() click to toggle source
# File lib/fluent/plugin/in_free.rb, line 46
def get_free_info
  ret = `free #{@option}`.split($/)
  ret.shift
  if @mode == 'actual'
    items = ret[1].split(/\s+/)
  else
    items = ret[0].split(/\s+/)
  end
  free_info = {
    'used'    => items[2],
    'free'    => items[3],
  }
  free_info
end