Class: Nephelae::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/nephelae/cloud_watch/metrics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace, options = {}) ⇒ Metrics

Returns a new instance of Metrics.



7
8
9
10
11
12
13
14
# File 'lib/nephelae/cloud_watch/metrics.rb', line 7

def initialize(namespace, options = {})
  #code to get the instance id from ec2 metadata
  @instance_id = options[:instance_id] || AWS.get_instance_id
  @params = {}
  @params['Action'] = 'PutMetricData'
  @params['Namespace'] = namespace
  @mcount = 0
end

Instance Attribute Details

#instance_idObject

Returns the value of attribute instance_id.



3
4
5
# File 'lib/nephelae/cloud_watch/metrics.rb', line 3

def instance_id
  @instance_id
end

#mcountObject (readonly)

Returns the value of attribute mcount.



5
6
7
# File 'lib/nephelae/cloud_watch/metrics.rb', line 5

def mcount
  @mcount
end

#namespaceObject

Returns the value of attribute namespace.



3
4
5
# File 'lib/nephelae/cloud_watch/metrics.rb', line 3

def namespace
  @namespace
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/nephelae/cloud_watch/metrics.rb', line 3

def params
  @params
end

Instance Method Details

#append_metric(name, value, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nephelae/cloud_watch/metrics.rb', line 16

def append_metric(name, value, options = {})
  dim_count = 1
  @mcount = @mcount + 1
  params["MetricData.member.#{@mcount}.MetricName"] = name
  params["MetricData.member.#{@mcount}.Value"] = value
  params["MetricData.member.#{@mcount}.Unit"] = options[:unit] || 'None'
  params["MetricData.member.#{@mcount}.Timestamp"] = options[:timestamp] if options[:timestamp]

  if @instance_id
    params["MetricData.member.#{@mcount}.Dimensions.member.#{dim_count}.Name"] = 'InstanceId'
    params["MetricData.member.#{@mcount}.Dimensions.member.#{dim_count}.Value"] = @instance_id
  end

end