Class: Aws::CloudWatch::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-cloudwatch/resource.rb

Associations collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • options ({}) (defaults to: {})

Options Hash (options):



13
14
15
# File 'lib/aws-sdk-cloudwatch/resource.rb', line 13

def initialize(options = {})
  @client = options[:client] || Client.new(options)
end

Instance Method Details

#alarm(name) ⇒ Alarm

Parameters:

  • name (String)

Returns:



26
27
28
29
30
31
# File 'lib/aws-sdk-cloudwatch/resource.rb', line 26

def alarm(name)
  Alarm.new(
    name: name,
    client: @client
  )
end

#alarms(options = {}) ⇒ Alarm::Collection

Examples:

Request syntax with placeholder values


alarms = cloud_watch.alarms({
  alarm_names: ["AlarmName"],
  alarm_name_prefix: "AlarmNamePrefix",
  state_value: "OK", # accepts OK, ALARM, INSUFFICIENT_DATA
  action_prefix: "ActionPrefix",
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :alarm_names (Array<String>)

    The names of the alarms.

  • :alarm_name_prefix (String)

    The alarm name prefix. If this parameter is specified, you cannot specify ‘AlarmNames`.

  • :state_value (String)

    The state value to be used in matching alarms.

  • :action_prefix (String)

    The action name prefix.

Returns:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/aws-sdk-cloudwatch/resource.rb', line 52

def alarms(options = {})
  batches = Enumerator.new do |y|
    resp = @client.describe_alarms(options)
    resp.each_page do |page|
      batch = []
      page.data.metric_alarms.each do |m|
        batch << Alarm.new(
          name: m.alarm_name,
          data: m,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  Alarm::Collection.new(batches)
end

#clientClient

Returns:



18
19
20
# File 'lib/aws-sdk-cloudwatch/resource.rb', line 18

def client
  @client
end

#metric(namespace, name) ⇒ Metric

Parameters:

  • namespace (String)
  • name (String)

Returns:



73
74
75
76
77
78
79
# File 'lib/aws-sdk-cloudwatch/resource.rb', line 73

def metric(namespace, name)
  Metric.new(
    namespace: namespace,
    name: name,
    client: @client
  )
end

#metrics(options = {}) ⇒ Metric::Collection

Examples:

Request syntax with placeholder values


metrics = cloud_watch.metrics({
  namespace: "Namespace",
  metric_name: "MetricName",
  dimensions: [
    {
      name: "DimensionName", # required
      value: "DimensionValue",
    },
  ],
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :namespace (String)

    The namespace to filter against.

  • :metric_name (String)

    The name of the metric to filter against.

  • :dimensions (Array<Types::DimensionFilter>)

    The dimensions to filter against.

Returns:



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/aws-sdk-cloudwatch/resource.rb', line 101

def metrics(options = {})
  batches = Enumerator.new do |y|
    resp = @client.list_metrics(options)
    resp.each_page do |page|
      batch = []
      page.data.metrics.each do |m|
        batch << Metric.new(
          namespace: m.namespace,
          name: m.metric_name,
          data: m,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  Metric::Collection.new(batches)
end