Class: PSI::Metrics
- Inherits:
-
Object
- Object
- PSI::Metrics
- Defined in:
- lib/psi/reading.rb
Overview
Pressure averages and the cumulative stall time for one PSI category.
Instance Attribute Summary collapse
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#avg(seconds) ⇒ Float?
Returns the rolling average for a window in seconds.
-
#avg10 ⇒ Float?
Ten-second average.
-
#avg300 ⇒ Float?
Three-hundred-second average.
-
#avg60 ⇒ Float?
Sixty-second average.
-
#initialize(averages:, total:) ⇒ Metrics
constructor
A new instance of Metrics.
-
#to_h ⇒ Hash
Converts dynamic averages and total time to a hash.
Constructor Details
#initialize(averages:, total:) ⇒ Metrics
Returns a new instance of Metrics.
8 9 10 11 |
# File 'lib/psi/reading.rb', line 8 def initialize(averages:, total:) @averages = averages.freeze @total = total end |
Instance Attribute Details
#total ⇒ Object (readonly)
Returns the value of attribute total.
6 7 8 |
# File 'lib/psi/reading.rb', line 6 def total @total end |
Instance Method Details
#avg(seconds) ⇒ Float?
Returns the rolling average for a window in seconds.
16 17 18 |
# File 'lib/psi/reading.rb', line 16 def avg(seconds) @averages[Integer(seconds)] end |
#avg10 ⇒ Float?
Returns ten-second average.
21 22 |
# File 'lib/psi/reading.rb', line 21 def avg10 = avg(10) # @return [Float, nil] sixty-second average |
#avg300 ⇒ Float?
Returns three-hundred-second average.
25 |
# File 'lib/psi/reading.rb', line 25 def avg300 = avg(300) |
#avg60 ⇒ Float?
Returns sixty-second average.
23 24 |
# File 'lib/psi/reading.rb', line 23 def avg60 = avg(60) # @return [Float, nil] three-hundred-second average |
#to_h ⇒ Hash
Converts dynamic averages and total time to a hash.
29 30 31 |
# File 'lib/psi/reading.rb', line 29 def to_h @averages.sort.to_h { |seconds, value| [:"avg#{seconds}", value] }.merge(total: total) end |