Class: Cloudscopes::Sample

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/cloudscopes/sample.rb', line 5

def name
  @name
end

#unitObject (readonly)

Returns the value of attribute unit.



5
6
7
# File 'lib/cloudscopes/sample.rb', line 5

def unit
  @unit
end

#valueObject (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_dataObject



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

#validObject



24
25
26
# File 'lib/cloudscopes/sample.rb', line 24

def valid
  ! @value.nil?
end