Class: Judoscale::MetricsStore
- Inherits:
-
Object
- Object
- Judoscale::MetricsStore
- Includes:
- Singleton
- Defined in:
- lib/judoscale/metrics_store.rb
Instance Attribute Summary collapse
-
#flushed_at ⇒ Object
readonly
Returns the value of attribute flushed_at.
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
Instance Method Summary collapse
- #clear ⇒ Object
- #flush ⇒ Object
-
#initialize ⇒ MetricsStore
constructor
A new instance of MetricsStore.
- #push(identifier, value, time = Time.now, queue_name = nil) ⇒ Object
Constructor Details
#initialize ⇒ MetricsStore
Returns a new instance of MetricsStore.
13 14 15 16 |
# File 'lib/judoscale/metrics_store.rb', line 13 def initialize @metrics = [] @flushed_at = Time.now end |
Instance Attribute Details
#flushed_at ⇒ Object (readonly)
Returns the value of attribute flushed_at.
11 12 13 |
# File 'lib/judoscale/metrics_store.rb', line 11 def flushed_at @flushed_at end |
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
11 12 13 |
# File 'lib/judoscale/metrics_store.rb', line 11 def metrics @metrics end |
Instance Method Details
#clear ⇒ Object
37 38 39 |
# File 'lib/judoscale/metrics_store.rb', line 37 def clear @metrics.clear end |
#flush ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/judoscale/metrics_store.rb', line 26 def flush @flushed_at = Time.now flushed_metrics = [] while (metric = @metrics.shift) flushed_metrics << metric end flushed_metrics end |
#push(identifier, value, time = Time.now, queue_name = nil) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/judoscale/metrics_store.rb', line 18 def push(identifier, value, time = Time.now, queue_name = nil) # If it's been two minutes since clearing out the store, stop collecting metrics. # There could be an issue with the reporter, and continuing to collect will consume linear memory. return if @flushed_at && @flushed_at < Time.now - 120 @metrics << Metric.new(identifier, value, time, queue_name) end |