class Fog::AWS::CloudWatch::Real
Public Class Methods
Initialize connection to Cloudwatch
Notes¶ ↑
options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection
Examples¶ ↑
elb = CloudWatch.new( :aws_access_key_id => your_aws_access_key_id, :aws_secret_access_key => your_aws_secret_access_key )
Parameters¶ ↑
-
options<~Hash> - config arguments for connection. Defaults to {}.
-
region<~String> - optional region to use. For instance, 'eu-west-1', 'us-east-1', etc.
-
Returns¶ ↑
-
CloudWatch
object with connection toAWS
.
# File lib/fog/aws/cloud_watch.rb, line 87 def initialize(options={}) @use_iam_profile = options[:use_iam_profile] @connection_options = options[:connection_options] || {} @instrumentor = options[:instrumentor] @instrumentor_name = options[:instrumentor_name] || 'fog.aws.cloud_watch' options[:region] ||= 'us-east-1' @region = options[:region] @host = options[:host] || "monitoring.#{options[:region]}.amazonaws.com" @path = options[:path] || '/' @persistent = options[:persistent] || false @port = options[:port] || 443 @scheme = options[:scheme] || 'https' @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options) setup_credentials(options) end
Public Instance Methods
Delete a list of alarms
Options¶ ↑
-
AlarmNames<~Array>: A list of alarms to be deleted
Returns¶ ↑
-
response<~Excon::Response>:
See Also¶ ↑
docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/index.html?API_DeleteAlarms.html
# File lib/fog/aws/requests/cloud_watch/delete_alarms.rb, line 18 def delete_alarms(alarm_names) options = {} options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names])) request({ 'Action' => 'DeleteAlarms', :parser => Fog::Parsers::AWS::CloudWatch::DeleteAlarms.new }.merge(options)) end
Retrieves history for the specified alarm
Options¶ ↑
-
AlarmName<~String>: The name of the alarm
-
EndDate<~DateTime>: The ending date to retrieve alarm history
-
HistoryItemType<~String>: The type of alarm histories to retrieve
-
MaxRecords<~Integer>: The maximum number of alarm history records to retrieve
-
NextToken<~String> The token returned by a previous call to indicate that there is more data available
-
StartData<~DateTime>: The starting date to retrieve alarm history
Returns¶ ↑
-
response<~Excon::Response>:
See Also¶ ↑
# File lib/fog/aws/requests/cloud_watch/describe_alarm_history.rb, line 23 def describe_alarm_history(options={}) request({ 'Action' => 'DescribeAlarmHistory', :parser => Fog::Parsers::AWS::CloudWatch::DescribeAlarmHistory.new }.merge(options)) end
Retrieves alarms with the specified names
Options¶ ↑
-
ActionPrefix<~String>: The action name prefix
-
AlarmNamePrefix<~String>: The alarm name prefix.
AlarmNames cannot be specified if this parameter is specified
-
AlarmNames<~Array>: A list of alarm names to retrieve information for.
-
MaxRecords<~Integer>: The maximum number of alarm descriptions to retrieve
-
NextToken<~String>: The token returned by a previous call to indicate that there is more data available
-
NextToken<~String> The token returned by a previous call to indicate that there is more data available
-
StateValue<~String>: The state value to be used in matching alarms
Returns¶ ↑
-
response<~Excon::Response>:
See Also¶ ↑
docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_DescribeAlarms.html
# File lib/fog/aws/requests/cloud_watch/describe_alarms.rb, line 25 def describe_alarms(options={}) if alarm_names = options.delete('AlarmNames') options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names])) end request({ 'Action' => 'DescribeAlarms', :parser => Fog::Parsers::AWS::CloudWatch::DescribeAlarms.new }.merge(options)) end
Retrieves all alarms for a single metric
Options¶ ↑
-
Dimensions<~Array>: a list of dimensions to filter against
Name : The name of the dimension Value : The value to filter against
-
MetricName<~String>: The name of the metric
-
Namespace<~String>: The namespace of the metric
-
Period<~Integer>: The period in seconds over which the statistic is applied
-
Statistics<~String>: The statistic for the metric
-
Unit<~String> The unit for the metric
Returns¶ ↑
-
response<~Excon::Response>:
See Also¶ ↑
docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_DescribeAlarms.html
# File lib/fog/aws/requests/cloud_watch/describe_alarms_for_metric.rb, line 25 def describe_alarms_for_metric(options) if dimensions = options.delete('Dimensions') options.merge!(AWS.indexed_param('Dimensions.member.%d.Name', dimensions.map {|dimension| dimension['Name']})) options.merge!(AWS.indexed_param('Dimensions.member.%d.Value', dimensions.map {|dimension| dimension['Value']})) end request({ 'Action' => 'DescribeAlarmsForMetric', :parser => Fog::Parsers::AWS::CloudWatch::DescribeAlarmsForMetric.new }.merge(options)) end
Disables actions for the specified alarms
Options¶ ↑
-
AlarmNames<~Array>: The names of the alarms to disable actions for
Returns¶ ↑
-
response<~Excon::Response>:
See Also¶ ↑
docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_DisableAlarmActions.html
# File lib/fog/aws/requests/cloud_watch/disable_alarm_actions.rb, line 18 def disable_alarm_actions(alarm_names) options = {} options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names])) request({ 'Action' => 'DisableAlarmActions', :parser => Fog::Parsers::AWS::CloudWatch::DisableAlarmActions.new }.merge(options)) end
Enables actions for the specified alarms
Options¶ ↑
-
AlarmNames<~Array>: The names of the alarms to enable actions for
Returns¶ ↑
-
response<~Excon::Response>:
See Also¶ ↑
docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_EnableAlarmActions.html
# File lib/fog/aws/requests/cloud_watch/enable_alarm_actions.rb, line 18 def enable_alarm_actions(alarm_names) options = {} options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names])) request({ 'Action' => 'EnableAlarmActions', :parser => Fog::Parsers::AWS::CloudWatch::EnableAlarmActions.new }.merge(options)) end
Fetch datapoints for a metric. At most 1440 datapoints will be returned, the most datapoints that can be queried is 50850 StartTime is capped to 2 weeks ago
Options¶ ↑
-
Namespace<~String>: the namespace of the metric
-
MetricName<~String>: the name of the metric
-
StartTime<~Datetime>: when to start fetching datapoints from (inclusive)
-
EndTime<~Datetime>: used to determine the last datapoint to fetch (exclusive)
-
Period<~Integer>: Granularity, in seconds of the returned datapoints. Must be a multiple of 60, and at least 60
-
Statistics<~Array>: An array of up to 5 strings, which name the statistics to return
-
Unit<~String>: The unit for the metric
-
Dimensions<~Array>: a list of dimensions to filter against (optional)
Name : The name of the dimension Value : The value to filter against
Returns¶ ↑
-
response<~Excon::Response>:
See Also¶ ↑
docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_GetMetricStatistics.html
# File lib/fog/aws/requests/cloud_watch/get_metric_statistics.rb, line 26 def get_metric_statistics(options={}) %w{Statistics StartTime EndTime Period MetricName Namespace}.each do |required_parameter| raise ArgumentError, "Must provide #{required_parameter}" unless options.key?(required_parameter) end statistics = options.delete 'Statistics' options.merge!(AWS.indexed_param('Statistics.member.%d', [*statistics])) if dimensions = options.delete('Dimensions') options.merge!(AWS.indexed_param('Dimensions.member.%d.Name', dimensions.map {|dimension| dimension['Name']})) options.merge!(AWS.indexed_param('Dimensions.member.%d.Value', dimensions.map {|dimension| dimension['Value']})) end request({ 'Action' => 'GetMetricStatistics', :parser => Fog::Parsers::AWS::CloudWatch::GetMetricStatistics.new }.merge(options)) end
List availabe metrics
Options¶ ↑
-
Dimensions<~Array>: a list of dimensions to filter against,
Name : The name of the dimension Value : The value to filter against
-
MetricName<~String>: The name of the metric to filter against
-
Namespace<~String>: The namespace to filter against
-
NextToken<~String> The token returned by a previous call to indicate that there is more data available
Returns¶ ↑
-
response<~Excon::Response>:
See Also¶ ↑
docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_ListMetrics.html
# File lib/fog/aws/requests/cloud_watch/list_metrics.rb, line 22 def list_metrics(options={}) if dimensions = options.delete('Dimensions') options.merge!(AWS.indexed_param('Dimensions.member.%d.Name', dimensions.map {|dimension| dimension['Name']})) options.merge!(AWS.indexed_param('Dimensions.member.%d.Value', dimensions.map {|dimension| dimension['Value']})) end request({ 'Action' => 'ListMetrics', :parser => Fog::Parsers::AWS::CloudWatch::ListMetrics.new }.merge(options)) end
Creates or updates an alarm and associates it with the specified Amazon CloudWatch
metric
Options¶ ↑
-
ActionsEnabled<~Boolean>: Indicates whether or not actions should be executed during any changes to the alarm's state
-
AlarmActions<~Array>: A list of actions to execute
-
AlarmDescription<~String>: The description for the alarm
-
AlarmName<~String> The unique name for the alarm
-
ComparisonOperator<~String>: The arithmetic operation to use for comparison
-
Dimensions<~Array>: a list of dimensions to filter against,
Name : The name of the dimension Value : The value to filter against
-
EvaluationPeriods<~Integer>: The number of periods over which data is compared to the specified threshold
-
InsufficientDataActions<~Array>: A list of actions to execute
-
MetricName<~String>: The name for the alarm's associated metric
-
Namespace<~String>: The namespace for the alarm's associated metric
-
OKActions<~Array>: A list of actions to execute
-
Period<~Integer>: The period in seconds over which the specified statistic is applied
-
Statistic<~String>: The statistic to apply to the alarm's associated metric
-
Threshold<~Double>: The value against which the specified statistic is compared
-
Unit<~String>: The unit for the alarm's associated metric
Returns¶ ↑
-
response<~Excon::Response>:
See Also¶ ↑
docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html
# File lib/fog/aws/requests/cloud_watch/put_metric_alarm.rb, line 33 def put_metric_alarm(options) if dimensions = options.delete('Dimensions') options.merge!(AWS.indexed_param('Dimensions.member.%d.Name', dimensions.map {|dimension| dimension['Name']})) options.merge!(AWS.indexed_param('Dimensions.member.%d.Value', dimensions.map {|dimension| dimension['Value']})) end if alarm_actions = options.delete('AlarmActions') options.merge!(AWS.indexed_param('AlarmActions.member.%d', [*alarm_actions])) end if insufficient_data_actions = options.delete('InsufficientDataActions') options.merge!(AWS.indexed_param('InsufficientDataActions.member.%d', [*insufficient_data_actions])) end if ok_actions = options.delete('OKActions') options.merge!(AWS.indexed_param('OKActions.member.%d', [*ok_actions])) end request({ 'Action' => 'PutMetricAlarm', :parser => Fog::Parsers::AWS::CloudWatch::PutMetricAlarm.new }.merge(options)) end
Publishes one or more data points to CloudWatch
. A new metric is created if necessary
Options¶ ↑
-
Namespace<~String>: the namespace of the metric data
-
MetricData<~Array>: the datapoints to publish of the metric
* MetricName<~String>: the name of the metric * Timestamp<~String>: the timestamp for the data point. If omitted defaults to the time at which the data is received by CloudWatch * Unit<~String>: the unit * Value<~Double> the value for the metric * StatisticValues<~Hash>: * Maximum<~Double>: the maximum value of the sample set * Sum<~Double>: the sum of the values of the sample set * SampleCount<~Double>: the number of samples used for the statistic set * Minimum<~Double>: the minimum value of the sample set * Dimensions<~Array>: the dimensions for the metric. From 0 to 10 may be included * Name<~String> * Value<~String>
Returns¶ ↑
-
response<~Excon::Response>:
See Also¶ ↑
docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_PutMetricData.html
# File lib/fog/aws/requests/cloud_watch/put_metric_data.rb, line 30 def put_metric_data(namespace, metric_data) options = {'Namespace' => namespace} #first index the dimensions for any of the datums that have dimensions metric_data.map! do |metric_datum| if dimensions = metric_datum.delete('Dimensions') metric_datum.merge!(AWS.indexed_param('Dimensions.member.%d.Name', dimensions.map {|dimension| dimension['Name']})) metric_datum.merge!(AWS.indexed_param('Dimensions.member.%d.Value', dimensions.map {|dimension| dimension['Value']})) end metric_datum end #then flatten out an hashes in the metric_data array metric_data.map! { |metric_datum| flatten_hash(metric_datum) } #then index the metric_data array options.merge!(AWS.indexed_param('MetricData.member.%d', [*metric_data])) #then finally flatten out an hashes in the overall options array options = flatten_hash(options) request({ 'Action' => 'PutMetricData', :parser => Fog::Parsers::AWS::CloudWatch::PutMetricData.new }.merge(options)) end
# File lib/fog/aws/cloud_watch.rb, line 107 def reload @connection.reset end
Temporarily sets the state of an alarm
Options¶ ↑
-
AlarmName<~String>: The names of the alarm
-
StateReason<~String>: The reason that this alarm is set to this specific state (in human-readable text format)
-
StateReasonData<~String>: The reason that this alarm is set to this specific state (in machine-readable JSON format)
-
StateValue<~String>: The value of the state
Returns¶ ↑
-
response<~Excon::Response>:
See Also¶ ↑
docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_SetAlarmState.html
# File lib/fog/aws/requests/cloud_watch/set_alarm_state.rb, line 21 def set_alarm_state(options) request({ 'Action' => 'SetAlarmState', :parser => Fog::Parsers::AWS::CloudWatch::SetAlarmState.new }.merge(options)) end
Private Instance Methods
# File lib/fog/aws/cloud_watch.rb, line 150 def _request(body, headers, idempotent, parser) @connection.request({ :body => body, :expects => 200, :headers => headers, :idempotent => idempotent, :method => 'POST', :parser => parser }) end
# File lib/fog/aws/requests/cloud_watch/put_metric_data.rb, line 55 def flatten_hash(starting) finishing = {} starting.each do |top_level_key, top_level_value| if top_level_value.is_a?(Hash) nested_hash = top_level_value nested_hash.each do |nested_key, nested_value| finishing["#{top_level_key}.#{nested_key}"] = nested_value end else finishing[top_level_key] = top_level_value end end return finishing end
# File lib/fog/aws/cloud_watch.rb, line 122 def request(params) refresh_credentials_if_expired idempotent = params.delete(:idempotent) parser = params.delete(:parser) body, headers = AWS.signed_params_v4( params, { 'Content-Type' => 'application/x-www-form-urlencoded' }, { :signer => @signer, :aws_session_token => @aws_session_token, :host => @host, :path => @path, :port => @port, :version => '2010-08-01', :method => 'POST' } ) if @instrumentor @instrumentor.instrument("#{@instrumentor_name}.request", params) do _request(body, headers, idempotent, parser) end else _request(body, headers, idempotent, parser) end end
# File lib/fog/aws/cloud_watch.rb, line 113 def setup_credentials(options) @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] @signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key,@region,'monitoring') end