Sha256: 62dfcd2b82e32c451b4d72408a36d2d976dcd5403af5e8eb8219393035d5da5e

Contents?: true

Size: 838 Bytes

Versions: 30

Compression:

Stored size: 838 Bytes

Contents

require 'find'

class Riemann::Babbler::Findfiles < Riemann::Babbler

  def init
    plugin.set_default(:service, 'find files')
    plugin.set_default(:interval, 60)
    plugin.set_default(:file_mask, '.*') # file search mask
    plugin.set_default(:dir, '/tmp/directory') # search in dir
    plugin.set_default(:age, 1440) # in minute
    plugin.states.set_default(:warning, 5)
  end

  def collect
    return [] unless File.directory?(plugin.dir)
    files = 0
    file_mask = Regexp.new(plugin.file_mask)
    Find.find(plugin.dir).each do |file|
      next unless File.file? file
      next unless file_mask.match file
      next unless Time.now.to_i - (plugin.age * 60) > File.new(file).mtime.to_i
      files += 1
    end
    { :service => plugin.service, :metric => files, :description => "Count files in #{plugin.dir}"}
  end

end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
riemann-babbler-1.4.0 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.9.7 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.9.6 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.9.5 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.9.4 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.9.3 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.9.1 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.9 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.8 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.7 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.6 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.5 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.4 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.3 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.2 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.1 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.3.0 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.2.9 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.2.8 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-1.2.7 lib/riemann/babbler/plugins/find_files.rb