class Cloudscopes::Sample
Attributes
name[R]
unit[R]
value[R]
Public Class Methods
new(namespace, metric)
click to toggle source
# 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
Public Instance Methods
dimensions()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/cloudscopes/sample.rb, line 35 def valid ! @value.nil? end