class Fluent::Plugin::DiskFree
Disk free command plugin class.
Constants
- DF_HEADER_COLMUS_LENGTH
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_diskfree.rb, line 49 def configure(conf) super # -P: use the POSIX output format @execute_command = "df -P #{@option} #{@mounted_path} 2> /dev/null" end
multi_workers_ready?()
click to toggle source
# File lib/fluent/plugin/in_diskfree.rb, line 58 def multi_workers_ready? true end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_diskfree.rb, line 65 def start super timer_execute(:in_diskfree, @refresh_interval, repeat: true, &method(:run_timer)) end
Private Instance Methods
diskfree()
click to toggle source
# File lib/fluent/plugin/in_diskfree.rb, line 78 def diskfree # Get df output. splited by line. result = `#{@execute_command}`.split(/\R/) # Remove df output header. result.shift result.map do |line| # split by space. data_list = line.split(/\s+/) # check header colmus length. log.error("Invalid df output format. #{line}") unless data_list.length == DF_HEADER_COLMUS_LENGTH # Calclate disk free percent. used_percent = ((data_list[2].to_f / data_list[1].to_f) * 100).floor(2) available_percent = ((data_list[3].to_f / data_list[1].to_f) * 100).floor(2) # output data. disk_info = { 'mounted_path' => replace_separator?(data_list[5]), 'disksize' => data_list[1].to_i, 'used' => data_list[2].to_i, 'used_percent' => @trim_percent ? used_percent : "#{used_percent}%", 'available' => data_list[3].to_i, 'available_percent' => @trim_percent ? available_percent : "#{available_percent}%", 'capacity' => data_list[4].to_i } disk_info end end
replace_separator?(path)
click to toggle source
# File lib/fluent/plugin/in_diskfree.rb, line 108 def replace_separator?(path) @replace_separator ? path.gsub(%r{/}, '_') : path end
run_timer()
click to toggle source
# File lib/fluent/plugin/in_diskfree.rb, line 115 def run_timer diskfree.each do |result| router.emit("#{@tag_prefix}.#{replace_separator?(@mounted_path)}", Fluent::Engine.now, result) end end