Class: PeriodicMonitor
Overview
Periodic monitor
This is very much a work in progress
Instance Attribute Summary collapse
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#iter ⇒ Object
readonly
Returns the value of attribute iter.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#time_interval ⇒ Object
Returns the value of attribute time_interval.
Instance Method Summary collapse
- #elapsed_time ⇒ Object
- #emit(log_line) ⇒ Object
- #incr! ⇒ Object
-
#initialize(extra_options = {}) ⇒ PeriodicMonitor
constructor
A new instance of PeriodicMonitor.
- #now ⇒ Object
- #periodically(*args, &block) ⇒ Object
- #progress(*stuff) ⇒ Object
- #rate ⇒ Object
- #ready? ⇒ Boolean
- #since ⇒ Object
Constructor Details
#initialize(extra_options = {}) ⇒ PeriodicMonitor
Returns a new instance of PeriodicMonitor.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wukong/periodic_monitor.rb', line 15 def initialize ={} @options = {} @options.deep_merge!( || {} ) @iter = 0 @start_time = now @last_report = @start_time @interval = ([:log_interval] || Settings[:log_interval]).to_i @interval = 1000 unless @interval >= 1 @time_interval = ([:log_seconds] || Settings[:log_seconds]).to_i end |
Instance Attribute Details
#interval ⇒ Object
Returns the value of attribute interval.
12 13 14 |
# File 'lib/wukong/periodic_monitor.rb', line 12 def interval @interval end |
#iter ⇒ Object (readonly)
Returns the value of attribute iter.
11 12 13 |
# File 'lib/wukong/periodic_monitor.rb', line 11 def iter @iter end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/wukong/periodic_monitor.rb', line 11 def @options end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
11 12 13 |
# File 'lib/wukong/periodic_monitor.rb', line 11 def start_time @start_time end |
#time_interval ⇒ Object
Returns the value of attribute time_interval.
13 14 15 |
# File 'lib/wukong/periodic_monitor.rb', line 13 def time_interval @time_interval end |
Instance Method Details
#elapsed_time ⇒ Object
60 61 62 |
# File 'lib/wukong/periodic_monitor.rb', line 60 def elapsed_time now - start_time end |
#emit(log_line) ⇒ Object
38 39 40 |
# File 'lib/wukong/periodic_monitor.rb', line 38 def emit log_line Log.info log_line end |
#incr! ⇒ Object
42 43 44 |
# File 'lib/wukong/periodic_monitor.rb', line 42 def incr! @iter += 1 end |
#periodically(*args, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/wukong/periodic_monitor.rb', line 26 def periodically *args, &block incr! if ready? @last_report = Time.now if block emit block.call(self, *args) else emit progress(*args) end end end |
#progress(*stuff) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/wukong/periodic_monitor.rb', line 50 def progress *stuff [ "%15d" % iter, "%7.1f"% elapsed_time, "sec", "%7.1f"% rate, "/sec", now.to_flat, *stuff ].flatten.join("\t") end |
#rate ⇒ Object
69 70 71 |
# File 'lib/wukong/periodic_monitor.rb', line 69 def rate iter.to_f / elapsed_time end |
#ready? ⇒ Boolean
46 47 48 |
# File 'lib/wukong/periodic_monitor.rb', line 46 def ready? (iter % @interval == 0) || (since > time_interval) end |
#since ⇒ Object
63 64 65 |
# File 'lib/wukong/periodic_monitor.rb', line 63 def since now - @last_report end |