Class: Cloudscopes::Sample
- Inherits:
-
Object
- Object
- Cloudscopes::Sample
- Defined in:
- lib/cloudscopes/sample.rb
Constant Summary collapse
- @@instanceid =
File.exists?(ec2_instanceid_file) ? File.read(ec2_instanceid_file).chomp : nil
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
-
#initialize(namespace, metric) ⇒ Sample
constructor
A new instance of Sample.
- #to_cloudwatch_metric_data ⇒ Object
- #valid ⇒ Object
Constructor Details
#initialize(namespace, metric) ⇒ Sample
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cloudscopes/sample.rb', line 10 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
#to_cloudwatch_metric_data ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/cloudscopes/sample.rb', line 28 def to_cloudwatch_metric_data return nil if @value.nil? data = { metric_name: @name, value: @value } data[:unit] = @unit if @unit data[:dimensions] = [ { name: "InstanceId", value: @@instanceid } ] unless @@instanceid.nil? data end |
#valid ⇒ Object
24 25 26 |
# File 'lib/cloudscopes/sample.rb', line 24 def valid ! @value.nil? end |