Class: Nephelae::CloudWatch

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log, logger, logger=

Constructor Details

#initialize(options = {}) ⇒ CloudWatch

Returns a new instance of CloudWatch.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/nephelae/cloud_watch/cloud_watch.rb', line 7

def initialize(options={})
  options[:region] ||= 'us-east-1'
  @host       = options[:host] || "monitoring.#{options[:region]}.amazonaws.com"
  @path       = options[:path]        || '/'
  @port       = options[:port]        || 443
  @scheme     = options[:scheme]      || 'https'
  @aws_access_key_id      = options[:aws_access_key_id]
  @aws_secret_access_key  = options[:aws_secret_access_key]
  @aws_session_token      = options[:aws_session_token]
  @aws_credentials_expire_at = options[:aws_credentials_expire_at]

  @url = "#{@scheme}://#{@host}:#{@port}#{@path}"

end

Instance Attribute Details

#aws_access_key_idObject

Returns the value of attribute aws_access_key_id.



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

def aws_access_key_id
  @aws_access_key_id
end

#aws_credentials_expire_atObject

Returns the value of attribute aws_credentials_expire_at.



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

def aws_credentials_expire_at
  @aws_credentials_expire_at
end

#aws_secret_access_keyObject

Returns the value of attribute aws_secret_access_key.



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

def aws_secret_access_key
  @aws_secret_access_key
end

#aws_session_tokenObject

Returns the value of attribute aws_session_token.



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

def aws_session_token
  @aws_session_token
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#put_metric(metric) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/nephelae/cloud_watch/cloud_watch.rb', line 45

def put_metric(metric)
  params = metric.params
  unless params.nil?
    cw_output = request(metric.params) unless params.nil?
    log.info(cw_output)
    cw_output
  end
end

#request(params) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/nephelae/cloud_watch/cloud_watch.rb', line 22

def request(params)
  body = AWS.signed_params(
    params,
    {
      :aws_access_key_id  => @aws_access_key_id,
      :aws_session_token  => @aws_session_token,
      :aws_secret_access_key => @aws_secret_access_key,
      :host               => @host,
      :path               => @path,
      :port               => @port,
      :version            => '2010-08-01'
    }
  )

  AWS.request(@url, {
     :body       => body,
     :expects    => 200,
     :headers    => { 'Content-Type' => 'application/x-www-form-urlencoded' },
     :host       => @host,
     :method     => 'POST'
   })
end