Sha256: 3bb6384d3431fd0a1ff6834e3b648a57bb164a8404a003731ba176310768ef51

Contents?: true

Size: 893 Bytes

Versions: 51

Compression:

Stored size: 893 Bytes

Contents

require 'find'

class Riemann::Babbler::Plugin::FindFiles < Riemann::Babbler::Plugin

  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)
    count_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
      count_files += 1
    end
    { :service => plugin.service, :metric => count_files, :description => "Count files in #{plugin.dir}" }
  end

end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
riemann-babbler-2.8.5 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.8.4 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.8.3 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.8.2 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.8.1 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.8.0 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.6.0 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.5.9 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.5.8 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.5.7 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.5.6 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.5.5 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.5.4 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.5.3 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.5.2 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.5.1 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.5.0 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.1.5 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.1.4 lib/riemann/babbler/plugins/find_files.rb
riemann-babbler-2.1.3.2 lib/riemann/babbler/plugins/find_files.rb