Class: DynoscaleRuby::Report
- Inherits:
-
Object
- Object
- DynoscaleRuby::Report
- Defined in:
- lib/dynoscale_ruby/report.rb
Constant Summary collapse
- REPORT_TTL =
minutes
5 * 60
Instance Attribute Summary collapse
-
#measurements ⇒ Object
readonly
Returns the value of attribute measurements.
-
#publish_timestamp ⇒ Object
readonly
Returns the value of attribute publish_timestamp.
Instance Method Summary collapse
- #add_measurement(current_time = Time.now, metric, source, metadata) ⇒ Object
- #add_measurements(measurements) ⇒ Object
- #expired?(current_time = Time.now) ⇒ Boolean
-
#initialize(publish_timestamp) ⇒ Report
constructor
A new instance of Report.
- #ready_to_publish?(current_time = Time.now) ⇒ Boolean
- #to_csv ⇒ Object
Constructor Details
#initialize(publish_timestamp) ⇒ Report
Returns a new instance of Report.
10 11 12 13 |
# File 'lib/dynoscale_ruby/report.rb', line 10 def initialize() @measurements = [] @publish_timestamp = end |
Instance Attribute Details
#measurements ⇒ Object (readonly)
Returns the value of attribute measurements.
8 9 10 |
# File 'lib/dynoscale_ruby/report.rb', line 8 def measurements @measurements end |
#publish_timestamp ⇒ Object (readonly)
Returns the value of attribute publish_timestamp.
8 9 10 |
# File 'lib/dynoscale_ruby/report.rb', line 8 def @publish_timestamp end |
Instance Method Details
#add_measurement(current_time = Time.now, metric, source, metadata) ⇒ Object
15 16 17 |
# File 'lib/dynoscale_ruby/report.rb', line 15 def add_measurement(current_time = Time.now, metric, source, ) @measurements << Measurement.new(current_time.to_i, metric, source, ) end |
#add_measurements(measurements) ⇒ Object
19 20 21 |
# File 'lib/dynoscale_ruby/report.rb', line 19 def add_measurements(measurements) @measurements.unshift(*measurements) end |
#expired?(current_time = Time.now) ⇒ Boolean
27 28 29 |
# File 'lib/dynoscale_ruby/report.rb', line 27 def expired?(current_time = Time.now) < (current_time - REPORT_TTL) end |
#ready_to_publish?(current_time = Time.now) ⇒ Boolean
23 24 25 |
# File 'lib/dynoscale_ruby/report.rb', line 23 def ready_to_publish?(current_time = Time.now) @measurements.any? && < current_time end |
#to_csv ⇒ Object
31 32 33 |
# File 'lib/dynoscale_ruby/report.rb', line 31 def to_csv @measurements.reduce(""){|t, m| "#{t}#{m.},#{m.metric},#{m.source},#{m.}\n"} end |