Class: Opower::TimeSeries::Metric
- Inherits:
-
Object
- Object
- Opower::TimeSeries::Metric
- Defined in:
- lib/time_series/metric.rb
Overview
Represents a metric that can be inserted into OpenTSDB instance through a [TSDBClient] object.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(config = {}) ⇒ Metric
constructor
Initializer for the Metric class.
-
#to_s ⇒ String
Converts the metric into the format required for use by ‘put` to insert into OpenTSDB.
Constructor Details
#initialize(config = {}) ⇒ Metric
Initializer for the Metric class.
18 19 20 21 22 23 24 25 |
# File 'lib/time_series/metric.rb', line 18 def initialize(config = {}) validate(config, [:name, :value]) @name = config[:name] @value = config[:value] = config[:timestamp] || Time.now.to_i = config[:tags] || {} end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/time_series/metric.rb', line 7 def name @name end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
7 8 9 |
# File 'lib/time_series/metric.rb', line 7 def end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/time_series/metric.rb', line 7 def end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/time_series/metric.rb', line 7 def value @value end |
Instance Method Details
#to_s ⇒ String
Converts the metric into the format required for use by ‘put` to insert into OpenTSDB.
30 31 32 33 34 35 |
# File 'lib/time_series/metric.rb', line 30 def to_s result = '' # Format the string for OpenTSDB .each { |key, value| result += "#{key}=#{value} " } [@name, , @value, result.rstrip].join(' ') end |