Class: Cloudscopes::Sample
- Inherits:
-
Object
- Object
- Cloudscopes::Sample
- Defined in:
- lib/cloudscopes/sample.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #dimensions ⇒ Object
-
#initialize(namespace, metric) ⇒ Sample
constructor
A new instance of Sample.
- #to_cloudwatch_metric_data ⇒ Object
- #valid ⇒ Object
Constructor Details
#initialize(namespace, metric) ⇒ Sample
Returns a new instance of Sample.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cloudscopes/sample.rb', line 21 def initialize(namespace, metric) @name = metric['name'] @unit = metric['unit'] @value = nil begin return if metric['requires'] and ! Cloudscopes.get_binding.eval(metric['requires']) @value = Cloudscopes.get_binding.eval(metric['value']) rescue => e STDERR.puts("Error evaluating #{@name}: #{e}") puts e.backtrace end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/cloudscopes/sample.rb', line 5 def name @name end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
5 6 7 |
# File 'lib/cloudscopes/sample.rb', line 5 def unit @unit end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/cloudscopes/sample.rb', line 5 def value @value end |
Instance Method Details
#dimensions ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cloudscopes/sample.rb', line 7 def dimensions Cloudscopes.data_dimensions.collect do |key,value| begin if ! value.start_with?('"') and value.include?('#') # user wants to expand a string expression, but can't be bothered with escaping double quotes { name: key, value: Cloudscopes.get_binding.eval('"' + value + '"') } else { name: key, value: Cloudscopes.get_binding.eval(value) } end rescue NameError # assume the user meant to send the static text { name: key, value: value } end end end |
#to_cloudwatch_metric_data ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/cloudscopes/sample.rb', line 39 def to_cloudwatch_metric_data return nil if @value.nil? data = { metric_name: @name, value: @value } data[:unit] = @unit if @unit data[:dimensions] = dimensions data end |
#valid ⇒ Object
35 36 37 |
# File 'lib/cloudscopes/sample.rb', line 35 def valid ! @value.nil? end |