Class: SolidObserver::ChartBuffer
- Inherits:
-
Object
- Object
- SolidObserver::ChartBuffer
- Defined in:
- lib/solid_observer/chart_buffer.rb
Constant Summary collapse
- INSTANCE_MUTEX =
Mutex.new
Class Method Summary collapse
Instance Method Summary collapse
- #append(value, at: Time.now) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ ChartBuffer
constructor
A new instance of ChartBuffer.
- #recent(window_seconds) ⇒ Object
Constructor Details
#initialize ⇒ ChartBuffer
Returns a new instance of ChartBuffer.
27 28 29 30 31 |
# File 'lib/solid_observer/chart_buffer.rb', line 27 def initialize @mutex = Mutex.new @samples = [] @cap = nil end |
Class Method Details
.append(value, at: Time.now) ⇒ Object
8 9 10 |
# File 'lib/solid_observer/chart_buffer.rb', line 8 def append(value, at: Time.now) instance.append(value, at: at) end |
.clear ⇒ Object
16 17 18 |
# File 'lib/solid_observer/chart_buffer.rb', line 16 def clear instance.clear end |
.recent(window_seconds) ⇒ Object
12 13 14 |
# File 'lib/solid_observer/chart_buffer.rb', line 12 def recent(window_seconds) instance.recent(window_seconds) end |
Instance Method Details
#append(value, at: Time.now) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/solid_observer/chart_buffer.rb', line 33 def append(value, at: Time.now) sample = {t: at.to_i, v: value.to_i} @mutex.synchronize { store_sample(sample) } sample end |
#clear ⇒ Object
49 50 51 52 53 54 |
# File 'lib/solid_observer/chart_buffer.rb', line 49 def clear @mutex.synchronize do @samples.clear @cap = nil end end |
#recent(window_seconds) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/solid_observer/chart_buffer.rb', line 41 def recent(window_seconds) cutoff = Time.now.to_i - window_seconds.to_i @mutex.synchronize do @samples.select { |sample| sample[:t] >= cutoff }.map(&:dup) end end |