CloudWatch

Amazon CloudWatch Monitoring Service (http://aws.amazon.com/cloudwatch)

Version

2009.08.26

Copyright

2006-2010 Ryan Parman, Foleeo, Inc., and contributors.

License

Simplified BSD Licensehttp://opensource.org/licenses/bsd-license.php

See Also

CloudFusionhttp://getcloudfusion.com
Amazon CloudWatchhttp://aws.amazon.com/cloudwatch

Constants

CW_DEFAULT_URL

Specify the default queue URL.

AmazonCloudWatch

Container for all Amazon CloudWatch-related methods.  Inherits additional methods from CloudFusion.

Extends

CloudFusion

Functions

__construct()

public function __construct($key =  null,
$secret_key =  null)

The constructor

Access

public

Parameters

keystring (Optional) Your Amazon API Key.  If blank, it will look for the AWS_KEY constant.
secret_keystring (Optional) Your Amazon API Secret Key.  If blank, it will look for the AWS_SECRET_KEY constant.

Returns

boolean false if no valid values are set, otherwise true.

list_metrics()

public function list_metrics($opt =  null)

Returns a list of up to 500 valid metrics for which there is recorded data available to a you and a NextToken string that can be used to query for the next set of results.

Access

public

Parameters

optarray (Required) Associative array of parameters which can have the following keys:

Keys for the $opt parameter

NextTokenstring (Optional) Allows you to retrieve the next set of results for your ListMetrics query.
returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

ResponseCore object

Examples

AmazonCloudWatch::list_metrics
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// List metrics
$cw = new AmazonCloudWatch();
$response = $cw->list_metrics();

// Success?
var_dump($response->isOK());

/** [Expected output] 
bool(true)
*/
?>
AmazonCloudWatch::list_metrics + NextToken
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// List metrics
$cw = new AmazonCloudWatch();
$response = $cw->list_metrics(array(
	'NextToken' => 't' // Invalid
));

// Success?
var_dump($response->body->Error->Message);

/** [Expected output] 
object(SimpleXMLElement)#7 (1) {
  [0]=>
  string(17) "Invalid nextToken"
}
*/
?>

See Also

AWS Methodhttp://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/index.html?API-ListMetrics.html

get_metric_statistics()

public function get_metric_statistics($measure_name,  
$statistics,  
$unit,  
$start_time,  
$end_time,  
$opt =  null)

Returns data for one or more statistics of given a metric.

Access

public

Parameters

measure_namestring (Required) The measure name that corresponds to the measure for the gathered metric.  See http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/index.html?arch-AmazonCloudWatch-metricscollected.html for a list of available measurements.
statisticsstring | array (Required) The statistics to be returned for the given metric.  You can pass a string for a single statistic, or an indexed array for multiple statistics.  See http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/index.html?arch-Amazon-CloudWatch-statistics.html for a list of available statistics.
unitstring (Required) The standard unit of measurement for a given Measure.  See http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/index.html?DT_StandardUnit.htmlfor a list of available units.
start_timestring (Required) A time stamp representing the beginning of the period to get results for.  Looks for an ISO-8601 formatted time stamp, but can convert any understandable time stamp into the correct format automatically.
end_timestring (Required) A time stamp representing the end of the period to get results for.  Looks for an ISO-8601 formatted time stamp, but can convert any understandable time stamp into the correct format automatically.
optarray (Required) Associative array of parameters which can have the following keys:

Keys for the $opt parameter

CustomUnitarray (Optional) The user-defined CustomUnit applied to a Measure.
Dimensionsarray (Optional) Allows you to specify one Dimension to further filter metric data on.  If you don’t specify a dimension, the service returns the aggregate of all the measures with the given measure name and time range.  See http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/index.html?arch-Amazon-CloudWatch-dimensions.html for a list of available dimensions.
Namespacearray (Optional) The namespace corresponding to the service of interest.  For example, “AWS/EC2” represents Amazon EC2.
Periodinteger (Required) The granularity (in seconds) of the returned datapoints.  Must be a multiple of 60.  Defaults to 60.
returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

ResponseCore object

Examples

AmazonCloudWatch::get_metric_statistics
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Get metrics
$cw = new AmazonCloudWatch();
$response = $cw->get_metric_statistics('CPUUtilization', 'Average', 'Percent', '1 August 2009', '2 August 2009');

// Success?
var_dump($response->isOK());

/** [Expected output] 
bool(true)
*/
?>
AmazonCloudWatch::get_metric_statistics + Statistic array
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Get metrics
$cw = new AmazonCloudWatch();
$response = $cw->get_metric_statistics('CPUUtilization', array('Average', 'Sum'), 'Percent', '1 August 2009', '2 August 2009');

// Success?
var_dump($response->isOK());

/** [Expected output] 
bool(true)
*/
?>
AmazonCloudWatch::get_metric_statistics + Optional parameters
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Get metrics
$cw = new AmazonCloudWatch();
$response = $cw->get_metric_statistics('CPUUtilization', 'Average', 'Percent', '1 August 2009', '31 August 2009', array(
	'Namespace' => 'AWS/EC2',
	'Period' => 1800
));

// Success?
var_dump($response->isOK());

/** [Expected output] 
bool(true)
*/
?>

See Also

AWS Methodhttp://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/index.html?API_GetMetricStatistics.html