This plugin provides native instrumentation for monitoring and metrics collection, including:health, usage, and various metrics of filesystem attributes.
bin/check-file-size.rb - I had a need to loop through several files in a directory and alert when the threshold was breach .. either warning or critical. Here's a snippet .. let me know if it's worth adding it to the base
option :directory,
description: 'Directory to stat (full path)',
short: '-d DIR',
long: '--dir DIR',
required: false
def stat_directory
begin
Subtract two for '.' and '..'
num_files = Dir.entries(config[:directory]).count - 2
rescue
unknown "Error listing files in #{config[:directory]}"
end
# Create an empty array.
critical_values = Array[]
warning_values = Array[]
# Loop through the directory array.
d = Dir.entries(config[:directory]).select {|f| !File.directory? f}
# puts d
#Dir.open(config[:directory]).each do |file_name|
d.each do |file_name|
#next if File.directory? file_name
temp= "#{config[:directory]}/#{file_name}"
stat = File.stat(temp)
$stdout.puts stat.inspect if config[:debug] == true
@file_size = stat.size
if @file_size >= config[:crit].to_i
# critical "#{config[:file]} is greater than #{format_bytes(config[:crit].to_i)} bytes! [actual size: #{format_bytes(@file_size)} bytes]"
# critical_values.push ("#{file_name} size: #{format_bytes(@file_size)} bytes" + "\r\n")
critical_values.push ("#{file_name} size: #{format_bytes(@file_size)} bytes")
elsif @file_size >= config[:warn].to_i
# warning "#{config[:file]} is greater than #{format_bytes(config[:warn].to_i)} bytes! [actual size: #{format_bytes(@file_size)} bytes]"
warning_values.push ("#{file_name} size: #{format_bytes(@file_size)} bytes")
end
end
if critical_values.any?
critical "#{critical_values} is/are greater than #{format_bytes(config[:crit].to_i)} bytes!"
elsif warning_values.any?
warning "#{warning_values} is/are greater than #{format_bytes(config[:warn].to_i)} bytes! "
else
ok "All files in the directory is/are within size limit"
end
bin/check-file-size.rb - I had a need to loop through several files in a directory and alert when the threshold was breach .. either warning or critical. Here's a snippet .. let me know if it's worth adding it to the base
option :directory, description: 'Directory to stat (full path)', short: '-d DIR', long: '--dir DIR', required: false
def stat_directory begin
Subtract two for '.' and '..'
end