2011-05-16 05:48:09 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class CloudWatch
|
|
|
|
class Real
|
|
|
|
|
|
|
|
require 'fog/aws/parsers/cloud_watch/put_metric_data'
|
|
|
|
|
|
|
|
# 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
|
2011-09-10 06:32:12 -04:00
|
|
|
# * Timestamp<~String>: the timestamp for the data point. If omitted defaults to the time at which the data is received by CloudWatch
|
2011-05-16 05:48:09 -04:00
|
|
|
# * 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
|
|
|
|
# http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_PutMetricData.html
|
|
|
|
#
|
2011-09-10 06:32:12 -04:00
|
|
|
|
2011-05-16 05:48:09 -04:00
|
|
|
def put_metric_data(namespace, metric_data)
|
2011-05-19 10:11:50 -04:00
|
|
|
options = {'Namespace' => namespace}
|
2011-09-10 06:32:12 -04:00
|
|
|
|
2011-05-19 10:11:50 -04:00
|
|
|
#first index the dimensions for any of the datums that have dimensions
|
|
|
|
metric_data.collect! do |metric_datum|
|
|
|
|
if dimensions = metric_datum.delete('Dimensions')
|
|
|
|
metric_datum.merge!(AWS.indexed_param('Dimensions.member.%d.Name', dimensions.collect {|dimension| dimension['Name']}))
|
|
|
|
metric_datum.merge!(AWS.indexed_param('Dimensions.member.%d.Value', dimensions.collect {|dimension| dimension['Value']}))
|
|
|
|
end
|
|
|
|
metric_datum
|
2011-05-16 05:48:09 -04:00
|
|
|
end
|
2011-05-19 10:11:50 -04:00
|
|
|
#then flatten out an hashes in the metric_data array
|
|
|
|
metric_data.collect! { |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)
|
2011-09-10 06:32:12 -04:00
|
|
|
|
2011-05-16 05:48:09 -04:00
|
|
|
request({
|
2011-05-19 10:11:50 -04:00
|
|
|
'Action' => 'PutMetricData',
|
|
|
|
:parser => Fog::Parsers::AWS::CloudWatch::PutMetricData.new
|
2011-05-16 05:48:09 -04:00
|
|
|
}.merge(options))
|
|
|
|
end
|
2011-05-19 10:11:50 -04:00
|
|
|
private
|
2011-09-10 06:32:12 -04:00
|
|
|
|
2011-05-19 10:11:50 -04:00
|
|
|
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
|
2011-05-16 05:48:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|