Class: NewRelic::Binding::Metric
- Inherits:
-
Object
- Object
- NewRelic::Binding::Metric
- Defined in:
- lib/newrelic_platform_binding/metric.rb
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sum_of_squares ⇒ Object
readonly
Returns the value of attribute sum_of_squares.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #aggregate(metric) ⇒ Object
-
#initialize(component, name, input_value, options = {}) ⇒ Metric
constructor
A new instance of Metric.
- #to_hash ⇒ Object
Constructor Details
#initialize(component, name, input_value, options = {}) ⇒ Metric
Returns a new instance of Metric.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/newrelic_platform_binding/metric.rb', line 7 def initialize(component, name, input_value, = {} ) value = input_value.to_f @component = component @name = name @value = value if () @count = [:count].to_i @min = [:min].to_f @max = [:max].to_f @sum_of_squares = [:sum_of_squares].to_f else PlatformLogger.warn("Metric #{@name} count, min, max, and sum_of_squares are all required if one is set, falling back to value only") unless .size == 0 @count = 1 @min = value @max = value @sum_of_squares = (value * value) end end |
Instance Attribute Details
#component ⇒ Object (readonly)
Returns the value of attribute component.
5 6 7 |
# File 'lib/newrelic_platform_binding/metric.rb', line 5 def component @component end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
5 6 7 |
# File 'lib/newrelic_platform_binding/metric.rb', line 5 def count @count end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
5 6 7 |
# File 'lib/newrelic_platform_binding/metric.rb', line 5 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
5 6 7 |
# File 'lib/newrelic_platform_binding/metric.rb', line 5 def min @min end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/newrelic_platform_binding/metric.rb', line 5 def name @name end |
#sum_of_squares ⇒ Object (readonly)
Returns the value of attribute sum_of_squares.
5 6 7 |
# File 'lib/newrelic_platform_binding/metric.rb', line 5 def sum_of_squares @sum_of_squares end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/newrelic_platform_binding/metric.rb', line 5 def value @value end |
Instance Method Details
#aggregate(metric) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/newrelic_platform_binding/metric.rb', line 26 def aggregate(metric) @value += metric.value @count += metric.count @min = [@min, metric.min].min @max = [@max, metric.max].max @sum_of_squares += metric.sum_of_squares end |
#to_hash ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/newrelic_platform_binding/metric.rb', line 34 def to_hash { name => [ @value, @count, @min, @max, @sum_of_squares ] } end |