Class: AwsInstanceList::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_instance_list/metric.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region: 'eu-west-1') ⇒ Metric

Returns a new instance of Metric.



9
10
11
# File 'lib/aws_instance_list/metric.rb', line 9

def initialize region: 'eu-west-1'
  @client=Aws::CloudWatch::Client.new region: region
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/aws_instance_list/metric.rb', line 7

def client
  @client
end

Instance Method Details

#free_storage_space(db_instance_identifier) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/aws_instance_list/metric.rb', line 21

def free_storage_space db_instance_identifier
  resp=statistics( {
    namespace: "AWS/RDS",
    metric_name: "FreeStorageSpace",
    dimensions: [
      {
        name: "DBInstanceIdentifier",
        value: db_instance_identifier,
      },
    ],
    start_time: Time.now - 600,
    end_time: Time.now ,
    period: 60,
    statistics: ["Minimum"]
  })

  resp.datapoints.last.minimum / ( 1024.0 ** 3)

end

#list(options) ⇒ Object



17
18
19
# File 'lib/aws_instance_list/metric.rb', line 17

def list options
  client.list_metrics options
end

#statistics(options) ⇒ Object



13
14
15
# File 'lib/aws_instance_list/metric.rb', line 13

def statistics options
  client.get_metric_statistics options
end