put_metric_data ( $namespace, $metric_data, $opt )

Publishes metric data points to Amazon CloudWatch. Amazon Cloudwatch associates the data points with the specified metric. If the specified metric does not exist, Amazon CloudWatch creates the metric.

If you create a metric with the PutMetricData action, allow up to fifteen minutes for the metric to appear in calls to the ListMetrics action.

The size of aPutMetricDatarequest is limited to 8 KB for HTTP GET requests and 40 KB for HTTP POST requests.

Although the Value parameter accepts numbers of type Double, Amazon CloudWatch truncates values with very large exponents. Values with base-10 exponents greater than 126 (1 x 10^126) are truncated. Likewise, values with base-10 exponents less than -130 (1 x 10^-130) are also truncated.

Access

public

Parameters

Parameter

Type

Required

Description

$namespace

string

Required

The namespace for the metric data. [Constraints: The value must be between 1 and 255 characters, and must match the following regular expression pattern: [^:].*]

$metric_data

array

Required

A list of data describing the metric.

  • x - array - Optional - This represents a simple array index.
    • MetricName - string - Required - The name of the metric.
    • Dimensions - array - Optional - A list of dimensions associated with the metric.
      • x - array - Optional - This represents a simple array index.
        • Name - string - Required - The name of the dimension.
        • Value - string - Required - The value representing the dimension measurement
    • Timestamp - string - Optional - The time stamp used for the metric. If not specified, the default value is set to the time the metric data was received. May be passed as a number of seconds since UNIX Epoch, or any string compatible with strtotime().
    • Value - double - Optional - The value for the metric.

      Although the Value parameter accepts numbers of type Double, Amazon CloudWatch truncates values with very large exponents. Values with base-10 exponents greater than 126 (1 x 10^126) are truncated. Likewise, values with base-10 exponents less than -130 (1 x 10^-130) are also truncated.

    • StatisticValues - array - Optional - A set of statistical values describing the metric.
      • x - array - Optional - This represents a simple array index.
        • SampleCount - double - Required - The number of samples used for the statistic set.
        • Sum - double - Required - The sum of values for the sample set.
        • Minimum - double - Required - The minimum value of the sample set.
        • Maximum - double - Required - The maximum value of the sample set.
    • Unit - string - Optional - The unit of the metric. [Allowed values: Seconds, Microseconds, Milliseconds, Bytes, Kilobytes, Megabytes, Gigabytes, Terabytes, Bits, Kilobits, Megabits, Gigabits, Terabits, Percent, Count, Bytes/Second, Kilobytes/Second, Megabytes/Second, Gigabytes/Second, Terabytes/Second, Bits/Second, Kilobits/Second, Megabits/Second, Gigabits/Second, Terabits/Second, Count/Second, None]

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples

Push custom metric data into CloudWatch.

$cw = new AmazonCloudWatch();

$response = $cw->put_metric_data('Custom/', array(
	array( // First data set
		'MetricName' => 'MyData',
		'Dimensions' => array(
			array('Name' => 'CustomAttribute1', 'Value' => 'CustomAttributeValue1'),
			array('Name' => 'CustomAttribute2', 'Value' => 'CustomAttributeValue2'),
		),
		'Timestamp' => 'today, midnight GMT',
		'StatisticValues' => array(
			'SampleCount' => 100,
			'Sum' => 1234567890,
			'Minimum' => 0,
			'Maximum' => 9999999999
		),
		'Unit' => 'Bits'
	),
));

// Success?
var_dump($response->isOK());
Result:
bool(true)

Source

Method defined in services/cloudwatch.class.php | Toggle source view (21 lines) | View on GitHub

public function put_metric_data($namespace, $metric_data, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['Namespace'] = $namespace;

    // Handle Timestamps
    for ($i = 0, $max = count($metric_data); $i < $max; $i++)
    {
        if (isset($metric_data[$i]['Timestamp']))
        {
            $metric_data[$i]['Timestamp'] = $this->util->convert_date_to_iso8601($metric_data[$i]['Timestamp']);
        }
    }

    // Required parameter
    $opt = array_merge($opt, CFComplexType::map(array(
        'MetricData' => (is_array($metric_data) ? $metric_data : array($metric_data))
    ), 'member'));

    return $this->authenticate('PutMetricData', $opt, $this->hostname);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback