class Riemann::Tools::DirFilesCount
Public Class Methods
new()
click to toggle source
# File lib/riemann/tools/dir_files_count.rb, line 17 def initialize @dir = opts.fetch(:directory) @service_prefix = opts.fetch(:service_prefix) @warning = opts.fetch(:warning, nil) @critical = opts.fetch(:critical, nil) @alert_on_missing = opts.fetch(:alert_on_missing) end
Public Instance Methods
state(metric)
click to toggle source
# File lib/riemann/tools/dir_files_count.rb, line 45 def state(metric) if @critical && metric > @critical 'critical' elsif @warning && metric > @warning 'warning' else 'ok' end end
tick()
click to toggle source
# File lib/riemann/tools/dir_files_count.rb, line 25 def tick if Dir.exist?(@dir) metric = Dir.entries(@dir).size - 2 report( service: "#{@service_prefix} #{@dir}", metric: metric, state: state(metric), tags: ['dir_files_count'], ) elsif @alert_on_missing report( service: "#{@service_prefix} #{@dir} missing", description: "#{@service_prefix} #{@dir} does not exist", metric: metric, state: 'critical', tags: ['dir_files_count'], ) end end