class Fluent::DfInput

Constants

EXPECTED_DF_OUTPUT_COLS_LENGTH

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_df.rb, line 16
def configure(conf)
  super
  @command = "df -P #{@option} #{@target_mounts} 2> /dev/null"
end
run() click to toggle source
# File lib/fluent/plugin/in_df.rb, line 37
def run
  @loop.run
rescue => e
  $log.error "#{e.class.name} - #{e.message}"
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_df.rb, line 29
def shutdown
  super
  @loop.watchers.each { |w| w.detach }
  @loop.stop
  @thread.terminate
  @thread.join
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_df.rb, line 21
def start
  super
  @loop = Coolio::Loop.new
  @timer = DfInputTimerWatcher.new(@interval, true, &method(:watch))
  @loop.attach(@timer)
  @thread = Thread.new(&method(:run))
end

Private Instance Methods

df() click to toggle source
# File lib/fluent/plugin/in_df.rb, line 44
def df
  fss = `#{@command}`.split($/)
  fss.shift # remove header
  fss.map do |fs|
    f = fs.split(/\s+/)

    unless f.length == EXPECTED_DF_OUTPUT_COLS_LENGTH
      $log.warn "The output of the df command is unexpected. May not obtain the correct result."
    end

    df_info = {
      'fs'        => replace_slash_in(f[0]),
      'size'      => f[1],
      'used'      => f[2],
      'available' => f[3],
      'capacity'  => f[4] && @rm_percent ? f[4].delete('%') : f[4]
    }
    df_info['hostname'] = `hostname`.chomp if @hostname
    df_info
  end
end
replace_slash_in(fs) click to toggle source
# File lib/fluent/plugin/in_df.rb, line 66
def replace_slash_in(fs)
  @replace_slash ? fs.gsub(/\//, '_') : fs
end
tag_name(fs) click to toggle source
# File lib/fluent/plugin/in_df.rb, line 70
def tag_name(fs)
  @tag || (@tag_prefix.empty? ? fs : "#{@tag_prefix}.#{fs}")
end
watch() click to toggle source
# File lib/fluent/plugin/in_df.rb, line 74
def watch
  df.each do |result|
    fs = result.delete('fs')
    Fluent::Engine.emit(tag_name(fs), Fluent::Engine.now, result)
  end
end