Class: Riemann::Tools::DirFilesCount
- Inherits:
-
Object
- Object
- Riemann::Tools::DirFilesCount
- Includes:
- Riemann::Tools
- Defined in:
- lib/riemann/tools/dir_files_count.rb
Constant Summary
Constants included from Riemann::Tools
Instance Attribute Summary
Attributes included from Riemann::Tools
Instance Method Summary collapse
-
#initialize ⇒ DirFilesCount
constructor
A new instance of DirFilesCount.
- #state(metric) ⇒ Object
- #tick ⇒ Object
Methods included from Riemann::Tools
#attributes, #endpoint_name, included, #options, #report, #riemann, #run
Constructor Details
#initialize ⇒ DirFilesCount
Returns a new instance of DirFilesCount.
17 18 19 20 21 22 23 24 25 |
# File 'lib/riemann/tools/dir_files_count.rb', line 17 def initialize super @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 |
Instance Method Details
#state(metric) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/riemann/tools/dir_files_count.rb', line 47 def state(metric) if @critical && metric > @critical 'critical' elsif @warning && metric > @warning 'warning' else 'ok' end end |
#tick ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/riemann/tools/dir_files_count.rb', line 27 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 |