Class: Graphiterb::Monitors::DirectoryTree
- Inherits:
-
PeriodicMonitor
- Object
- PeriodicMonitor
- Graphiterb::Monitors::DirectoryTree
- Defined in:
- lib/graphiterb/monitors/directory_tree.rb
Overview
A class for monitoring the contents of a directory.
Will only monitor files modified within the last hour by default.
Defined Under Namespace
Classes: Directory
Instance Attribute Summary collapse
-
#filter_re ⇒ Object
A regular expression filter that must be matched by files within the root directory to be counted.
-
#root ⇒ Object
The root of the directory tree being monitored.
Attributes inherited from PeriodicMonitor
#current_iter, #iter, #iter_interval, #last_time, #main_scope, #options, #started_at, #time_interval
Instance Method Summary collapse
- #dirs ⇒ Object
- #get_metrics(metrics, since) ⇒ Object
-
#initialize(main_scope, root, options = {}) ⇒ DirectoryTree
constructor
A new instance of DirectoryTree.
Methods inherited from PeriodicMonitor
#enough_iterations?, #enough_time?, #inst_rate, #periodically, #rate, #run!, #scope, #sender, #since
Methods included from Utils::SystemInfo
#graphite_identifier, #hostname, #node_name
Constructor Details
#initialize(main_scope, root, options = {}) ⇒ DirectoryTree
Returns a new instance of DirectoryTree.
17 18 19 20 21 |
# File 'lib/graphiterb/monitors/directory_tree.rb', line 17 def initialize main_scope, root, ={} super(main_scope, ) self.root = File.(root) self.filter_re = self.[:filter_re] || /.*/ end |
Instance Attribute Details
#filter_re ⇒ Object
A regular expression filter that must be matched by files within the root directory to be counted.
15 16 17 |
# File 'lib/graphiterb/monitors/directory_tree.rb', line 15 def filter_re @filter_re end |
#root ⇒ Object
The root of the directory tree being monitored.
11 12 13 |
# File 'lib/graphiterb/monitors/directory_tree.rb', line 11 def root @root end |
Instance Method Details
#dirs ⇒ Object
23 24 25 |
# File 'lib/graphiterb/monitors/directory_tree.rb', line 23 def dirs @dirs ||= Dir[File.join(root, '*')].select{|d| File.directory?(d) }.map { |path| Directory.new(path, filter_re) } end |
#get_metrics(metrics, since) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/graphiterb/monitors/directory_tree.rb', line 27 def get_metrics metrics, since recent = Directory.recency_filter dirs.each do |dir| metrics << [scope(dir.name, 'num_files', graphite_identifier), dir.num_files(&recent) ] metrics << [scope(dir.name, 'size', graphite_identifier), dir.size(&recent) ] metrics << [scope(dir.name, 'lines', graphite_identifier), dir.line_counts(&recent) ] end end |