Class: GRI::Scheduler
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fake_descr_hash ⇒ Object
Returns the value of attribute fake_descr_hash.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#writers ⇒ Object
Returns the value of attribute writers.
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(loop, metrics) ⇒ Scheduler
constructor
A new instance of Scheduler.
- #process1(col_type, host, options) ⇒ Object
- #process_queue ⇒ Object
Constructor Details
#initialize(loop, metrics) ⇒ Scheduler
Returns a new instance of Scheduler.
5 6 7 8 9 10 |
# File 'lib/gri/scheduler.rb', line 5 def initialize loop, metrics @loop = loop @metrics = metrics @loop.on_detach {process_queue} @writers = [] end |
Instance Attribute Details
#fake_descr_hash ⇒ Object
Returns the value of attribute fake_descr_hash.
3 4 5 |
# File 'lib/gri/scheduler.rb', line 3 def fake_descr_hash @fake_descr_hash end |
#queue ⇒ Object
Returns the value of attribute queue.
3 4 5 |
# File 'lib/gri/scheduler.rb', line 3 def queue @queue end |
#writers ⇒ Object
Returns the value of attribute writers.
3 4 5 |
# File 'lib/gri/scheduler.rb', line 3 def writers @writers end |
Instance Method Details
#finalize ⇒ Object
55 56 57 |
# File 'lib/gri/scheduler.rb', line 55 def finalize @writers.each {|w| w.finalize if w.respond_to? :finalize} end |
#process1(col_type, host, options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gri/scheduler.rb', line 26 def process1 col_type, host, return if Config['nop'] collector = Collector.create(col_type, host, , @fake_descr_hash) {|records| for writer in @writers writer.write records end @metrics[:record_count] += records.size } if collector #puts "#{collector.class} (#{col_type}): #{host}" if $debug interval = (['interval'] || 300).to_i collector.interval = interval collector.timeout = [90, interval].min collector.on_error {@metrics[:error_count] += 1} collector.on_retry {@metrics[:retry_count] += 1} Log.info "[#{$$}] #{host}: collect #{col_type}" begin @loop.run if collector.sync? @loop.attach collector rescue SystemCallError Log.error "#{host}: ERROR: #{$!}" puts "#{host}: ERROR: #{$!}" if $debug @loop.detach collector end @metrics[:run_count] += 1 end end |
#process_queue ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gri/scheduler.rb', line 12 def process_queue while @loop.collectors.size < 5 host, = queue.shift break unless host next if host =~ /^GRIMETRICS/ ts = ['type'] col_types = ts ? ts.split(',') : ['snmp'] for col_type in col_types process1 col_type, host, end end end |