cloudwatch.class.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <?php
  2. /*
  3. * Copyright 2010-2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. /**
  17. *
  18. *
  19. * This is the <i>Amazon CloudWatch API Reference</i>. This guide provides detailed information about Amazon CloudWatch actions, data types,
  20. * parameters, and errors. For detailed information about Amazon CloudWatch features and their associated API calls, go to the <a
  21. * href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide">Amazon CloudWatch Developer Guide</a>.
  22. *
  23. * Amazon CloudWatch is a web service that enables you to publish, monitor, and manage various metrics, as well as configure alarm actions
  24. * based on data from metrics. For more information about this product go to <a
  25. * href="http://aws.amazon.com/cloudwatch">http://aws.amazon.com/cloudwatch</a>.
  26. *
  27. * Use the following links to get started using the <i>Amazon CloudWatch API Reference</i>:
  28. *
  29. * <ul> <li> <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_Operations.html">Actions</a>: An alphabetical
  30. * list of all Amazon CloudWatch actions.</li>
  31. *
  32. * <li> <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_Types.html">Data Types</a>: An alphabetical list
  33. * of all Amazon CloudWatch data types.</li>
  34. *
  35. * <li> <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/CommonParameters.html">Common Parameters</a>:
  36. * Parameters that all Query actions can use.</li>
  37. *
  38. * <li> <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/CommonErrors.html">Common Errors</a>: Client and
  39. * server errors that all actions can return.</li>
  40. *
  41. * <li> <a href="http://docs.amazonwebservices.com/general/latest/gr/index.html?rande.html">Regions and Endpoints</a>: Itemized regions and
  42. * endpoints for all AWS products.</li>
  43. *
  44. * <li> <a href="http://monitoring.amazonaws.com/doc/2010-08-01/CloudWatch.wsdl">WSDL Location</a>:
  45. * http://monitoring.amazonaws.com/doc/2010-08-01/CloudWatch.wsdl</li>
  46. *
  47. * </ul>
  48. *
  49. * @version Tue Aug 23 12:46:08 PDT 2011
  50. * @license See the included NOTICE.md file for complete information.
  51. * @copyright See the included NOTICE.md file for complete information.
  52. * @link http://aws.amazon.com/cloudwatch/Amazon CloudWatch
  53. * @link http://aws.amazon.com/documentation/cloudwatch/Amazon CloudWatch documentation
  54. */
  55. class AmazonCloudWatch extends CFRuntime
  56. {
  57. /*%******************************************************************************************%*/
  58. // CLASS CONSTANTS
  59. /**
  60. * Specify the default queue URL.
  61. */
  62. const DEFAULT_URL = 'monitoring.amazonaws.com';
  63. /**
  64. * Specify the queue URL for the US-East (Northern Virginia) Region.
  65. */
  66. const REGION_US_E1 = 'us-east-1';
  67. /**
  68. * Specify the queue URL for the US-West (Northern California) Region.
  69. */
  70. const REGION_US_W1 = 'us-west-1';
  71. /**
  72. * Specify the queue URL for the EU (Ireland) Region.
  73. */
  74. const REGION_EU_W1 = 'eu-west-1';
  75. /**
  76. * Specify the queue URL for the Asia Pacific (Singapore) Region.
  77. */
  78. const REGION_APAC_SE1 = 'ap-southeast-1';
  79. /**
  80. * Specify the queue URL for the Asia Pacific (Japan) Region.
  81. */
  82. const REGION_APAC_NE1 = 'ap-northeast-1';
  83. /*%******************************************************************************************%*/
  84. // SETTERS
  85. /**
  86. * This allows you to explicitly sets the region for the service to use.
  87. *
  88. * @param string $region (Required) The region to explicitly set. Available options are <REGION_US_E1>, <REGION_US_W1>, <REGION_EU_W1>, or <REGION_APAC_SE1>.
  89. * @return $this A reference to the current instance.
  90. */
  91. public function set_region($region)
  92. {
  93. $this->set_hostname('http://monitoring.'. $region .'.amazonaws.com');
  94. return $this;
  95. }
  96. /*%******************************************************************************************%*/
  97. // CONSTRUCTOR
  98. /**
  99. * Constructs a new instance of <AmazonCloudWatch>.
  100. *
  101. * @param string $key (Optional) Your Amazon API Key. If blank, it will look for the <code>AWS_KEY</code> constant.
  102. * @param string $secret_key (Optional) Your Amazon API Secret Key. If blank, it will look for the <code>AWS_SECRET_KEY</code> constant.
  103. * @return boolean false if no valid values are set, otherwise true.
  104. */
  105. public function __construct($key = null, $secret_key = null)
  106. {
  107. $this->api_version = '2010-08-01';
  108. $this->hostname = self::DEFAULT_URL;
  109. if (!$key && !defined('AWS_KEY'))
  110. {
  111. // @codeCoverageIgnoreStart
  112. throw new CW_Exception('No account key was passed into the constructor, nor was it set in the AWS_KEY constant.');
  113. // @codeCoverageIgnoreEnd
  114. }
  115. if (!$secret_key && !defined('AWS_SECRET_KEY'))
  116. {
  117. // @codeCoverageIgnoreStart
  118. throw new CW_Exception('No account secret was passed into the constructor, nor was it set in the AWS_SECRET_KEY constant.');
  119. // @codeCoverageIgnoreEnd
  120. }
  121. return parent::__construct($key, $secret_key);
  122. }
  123. /*%******************************************************************************************%*/
  124. // SERVICE METHODS
  125. /**
  126. *
  127. * Creates or updates an alarm and associates it with the specified Amazon CloudWatch metric. Optionally, this operation can associate one or
  128. * more Amazon Simple Notification Service resources with the alarm.
  129. *
  130. * When this operation creates an alarm, the alarm state is immediately set to <code>INSUFFICIENT_DATA</code>. The alarm is evaluated and its
  131. * <code>StateValue</code> is set appropriately. Any actions associated with the <code>StateValue</code> is then executed.
  132. *
  133. * When updating an existing alarm, its <code>StateValue</code> is left unchanged.
  134. *
  135. * @param string $alarm_name (Required) The descriptive name for the alarm. This name must be unique within the user's AWS account
  136. * @param string $metric_name (Required) The name for the alarm's associated metric.
  137. * @param string $namespace (Required) The namespace for the alarm's associated metric.
  138. * @param string $statistic (Required) The statistic to apply to the alarm's associated metric. [Allowed values: <code>SampleCount</code>, <code>Average</code>, <code>Sum</code>, <code>Minimum</code>, <code>Maximum</code>]
  139. * @param integer $period (Required) The period in seconds over which the specified statistic is applied.
  140. * @param integer $evaluation_periods (Required) The number of periods over which data is compared to the specified threshold.
  141. * @param double $threshold (Required) The value against which the specified statistic is compared.
  142. * @param string $comparison_operator (Required) The arithmetic operation to use when comparing the specified <code>Statistic</code> and <code>Threshold</code>. The specified <code>Statistic</code> value is used as the first operand. [Allowed values: <code>GreaterThanOrEqualToThreshold</code>, <code>GreaterThanThreshold</code>, <code>LessThanThreshold</code>, <code>LessThanOrEqualToThreshold</code>]
  143. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  144. * <li><code>AlarmDescription</code> - <code>string</code> - Optional - The description for the alarm. </li>
  145. * <li><code>ActionsEnabled</code> - <code>boolean</code> - Optional - Indicates whether or not actions should be executed during any changes to the alarm's state. </li>
  146. * <li><code>OKActions</code> - <code>string|array</code> - Optional - The list of actions to execute when this alarm transitions into an <code>OK</code> state from any other state. Each action is specified as an Amazon Resource Number (ARN). Currently the only action supported is publishing to an Amazon SNS topic or an Amazon Auto Scaling policy. Pass a string for a single value, or an indexed array for multiple values. </li>
  147. * <li><code>AlarmActions</code> - <code>string|array</code> - Optional - The list of actions to execute when this alarm transitions into an <code>ALARM</code> state from any other state. Each action is specified as an Amazon Resource Number (ARN). Currently the only action supported is publishing to an Amazon SNS topic or an Amazon Auto Scaling policy. Pass a string for a single value, or an indexed array for multiple values. </li>
  148. * <li><code>InsufficientDataActions</code> - <code>string|array</code> - Optional - The list of actions to execute when this alarm transitions into an <code>INSUFFICIENT_DATA</code> state from any other state. Each action is specified as an Amazon Resource Number (ARN). Currently the only action supported is publishing to an Amazon SNS topic or an Amazon Auto Scaling policy. Pass a string for a single value, or an indexed array for multiple values. </li>
  149. * <li><code>Dimensions</code> - <code>array</code> - Optional - The dimensions for the alarm's associated metric. <ul>
  150. * <li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
  151. * <li><code>Name</code> - <code>string</code> - Required - The name of the dimension. </li>
  152. * <li><code>Value</code> - <code>string</code> - Required - The value representing the dimension measurement </li>
  153. * </ul></li>
  154. * </ul></li>
  155. * <li><code>Unit</code> - <code>string</code> - Optional - The unit for the alarm's associated metric. [Allowed values: <code>Seconds</code>, <code>Microseconds</code>, <code>Milliseconds</code>, <code>Bytes</code>, <code>Kilobytes</code>, <code>Megabytes</code>, <code>Gigabytes</code>, <code>Terabytes</code>, <code>Bits</code>, <code>Kilobits</code>, <code>Megabits</code>, <code>Gigabits</code>, <code>Terabits</code>, <code>Percent</code>, <code>Count</code>, <code>Bytes/Second</code>, <code>Kilobytes/Second</code>, <code>Megabytes/Second</code>, <code>Gigabytes/Second</code>, <code>Terabytes/Second</code>, <code>Bits/Second</code>, <code>Kilobits/Second</code>, <code>Megabits/Second</code>, <code>Gigabits/Second</code>, <code>Terabits/Second</code>, <code>Count/Second</code>, <code>None</code>]</li>
  156. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  157. * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
  158. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  159. */
  160. public function put_metric_alarm($alarm_name, $metric_name, $namespace, $statistic, $period, $evaluation_periods, $threshold, $comparison_operator, $opt = null)
  161. {
  162. if (!$opt) $opt = array();
  163. $opt['AlarmName'] = $alarm_name;
  164. // Optional parameter
  165. if (isset($opt['OKActions']))
  166. {
  167. $opt = array_merge($opt, CFComplexType::map(array(
  168. 'OKActions' => (is_array($opt['OKActions']) ? $opt['OKActions'] : array($opt['OKActions']))
  169. ), 'member'));
  170. unset($opt['OKActions']);
  171. }
  172. // Optional parameter
  173. if (isset($opt['AlarmActions']))
  174. {
  175. $opt = array_merge($opt, CFComplexType::map(array(
  176. 'AlarmActions' => (is_array($opt['AlarmActions']) ? $opt['AlarmActions'] : array($opt['AlarmActions']))
  177. ), 'member'));
  178. unset($opt['AlarmActions']);
  179. }
  180. // Optional parameter
  181. if (isset($opt['InsufficientDataActions']))
  182. {
  183. $opt = array_merge($opt, CFComplexType::map(array(
  184. 'InsufficientDataActions' => (is_array($opt['InsufficientDataActions']) ? $opt['InsufficientDataActions'] : array($opt['InsufficientDataActions']))
  185. ), 'member'));
  186. unset($opt['InsufficientDataActions']);
  187. }
  188. $opt['MetricName'] = $metric_name;
  189. $opt['Namespace'] = $namespace;
  190. $opt['Statistic'] = $statistic;
  191. // Optional parameter
  192. if (isset($opt['Dimensions']))
  193. {
  194. $opt = array_merge($opt, CFComplexType::map(array(
  195. 'Dimensions' => $opt['Dimensions']
  196. ), 'member'));
  197. unset($opt['Dimensions']);
  198. }
  199. $opt['Period'] = $period;
  200. $opt['EvaluationPeriods'] = $evaluation_periods;
  201. $opt['Threshold'] = $threshold;
  202. $opt['ComparisonOperator'] = $comparison_operator;
  203. return $this->authenticate('PutMetricAlarm', $opt, $this->hostname);
  204. }
  205. /**
  206. * Publishes metric data points to Amazon CloudWatch. Amazon Cloudwatch associates the data points with the specified metric. If the specified
  207. * metric does not exist, Amazon CloudWatch creates the metric. If you create a metric with the <code>PutMetricData</code> action, allow up to
  208. * fifteen minutes for the metric to appear in calls to the ListMetrics action.
  209. *
  210. * The size of a <code>PutMetricData</code> request is limited to 8 KB for HTTP GET requests and 40 KB for HTTP POST requests.
  211. *
  212. * Amazon CloudWatch truncates values with very large exponents. Values with base-10 exponents greater than 126 (1 x 10^126) are truncated.
  213. * Likewise, values with base-10 exponents less than -130 (1 x 10^-130) are also truncated.
  214. *
  215. * @param string $namespace (Required) The namespace for the metric data. You cannot specify a namespace that begins with <code>AWS/</code>. Namespaces that begin with <code>AWS/</code> are reserved for other Amazon Web Services products that send metrics to Amazon CloudWatch.
  216. * @param array $metric_data (Required) A list of data describing the metric. <ul>
  217. * <li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
  218. * <li><code>MetricName</code> - <code>string</code> - Required - The name of the metric. </li>
  219. * <li><code>Dimensions</code> - <code>array</code> - Optional - A list of dimensions associated with the metric. <ul>
  220. * <li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
  221. * <li><code>Name</code> - <code>string</code> - Required - The name of the dimension. </li>
  222. * <li><code>Value</code> - <code>string</code> - Required - The value representing the dimension measurement </li>
  223. * </ul></li>
  224. * </ul></li>
  225. * <li><code>Timestamp</code> - <code>string</code> - 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 <php:strtotime()>.</li>
  226. * <li><code>Value</code> - <code>integer</code> - Optional - The value for the metric. <important>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. </important> </li>
  227. * <li><code>StatisticValues</code> - <code>array</code> - Optional - A set of statistical values describing the metric. Takes an associative array of parameters that can have the following keys: <ul>
  228. * <li><code>SampleCount</code> - <code>double</code> - Required - The number of samples used for the statistic set. </li>
  229. * <li><code>Sum</code> - <code>double</code> - Required - The sum of values for the sample set. </li>
  230. * <li><code>Minimum</code> - <code>double</code> - Required - The minimum value of the sample set. </li>
  231. * <li><code>Maximum</code> - <code>double</code> - Required - The maximum value of the sample set. </li>
  232. * </ul></li>
  233. * <li><code>Unit</code> - <code>string</code> - Optional - The unit of the metric. [Allowed values: <code>Seconds</code>, <code>Microseconds</code>, <code>Milliseconds</code>, <code>Bytes</code>, <code>Kilobytes</code>, <code>Megabytes</code>, <code>Gigabytes</code>, <code>Terabytes</code>, <code>Bits</code>, <code>Kilobits</code>, <code>Megabits</code>, <code>Gigabits</code>, <code>Terabits</code>, <code>Percent</code>, <code>Count</code>, <code>Bytes/Second</code>, <code>Kilobytes/Second</code>, <code>Megabytes/Second</code>, <code>Gigabytes/Second</code>, <code>Terabytes/Second</code>, <code>Bits/Second</code>, <code>Kilobits/Second</code>, <code>Megabits/Second</code>, <code>Gigabits/Second</code>, <code>Terabits/Second</code>, <code>Count/Second</code>, <code>None</code>]</li>
  234. * </ul></li>
  235. * </ul>
  236. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  237. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  238. * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
  239. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  240. */
  241. public function put_metric_data($namespace, $metric_data, $opt = null)
  242. {
  243. if (!$opt) $opt = array();
  244. $opt['Namespace'] = $namespace;
  245. // Handle Timestamps
  246. for ($i = 0, $max = count($metric_data); $i < $max; $i++)
  247. {
  248. if (isset($metric_data[$i]['Timestamp']))
  249. {
  250. $metric_data[$i]['Timestamp'] = $this->util->convert_date_to_iso8601($metric_data[$i]['Timestamp']);
  251. }
  252. }
  253. // Required parameter
  254. $opt = array_merge($opt, CFComplexType::map(array(
  255. 'MetricData' => (is_array($metric_data) ? $metric_data : array($metric_data))
  256. ), 'member'));
  257. return $this->authenticate('PutMetricData', $opt, $this->hostname);
  258. }
  259. /**
  260. *
  261. * Returns a list of valid metrics stored for the AWS account owner. Returned metrics can be used with GetMetricStatistics to obtain
  262. * statistical data for a given metric.
  263. *
  264. * Up to 500 results are returned for any one call. To retrieve further results, use returned <code>NextToken</code> values with subsequent
  265. * <code>ListMetrics</code> operations.
  266. *
  267. * If you create a metric with the PutMetricData action, allow up to fifteen minutes for the metric to appear in calls to the
  268. * <code>ListMetrics</code> action. Statistics about the metric, however, are available sooner using GetMetricStatistics.
  269. *
  270. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  271. * <li><code>Namespace</code> - <code>string</code> - Optional - The namespace to filter against. </li>
  272. * <li><code>MetricName</code> - <code>string</code> - Optional - The name of the metric to filter against. </li>
  273. * <li><code>Dimensions</code> - <code>array</code> - Optional - A list of dimensions to filter against. <ul>
  274. * <li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
  275. * <li><code>Name</code> - <code>string</code> - Required - The dimension name to be matched. </li>
  276. * <li><code>Value</code> - <code>string</code> - Optional - The value of the dimension to be matched. Specifying a <code>Name</code> without specifying a <code>Value</code> returns all values associated with that <code>Name</code>. </li>
  277. * </ul></li>
  278. * </ul></li>
  279. * <li><code>NextToken</code> - <code>string</code> - Optional - The token returned by a previous call to indicate that there is more data available. </li>
  280. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  281. * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
  282. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  283. */
  284. public function list_metrics($opt = null)
  285. {
  286. if (!$opt) $opt = array();
  287. // Optional parameter
  288. if (isset($opt['Dimensions']))
  289. {
  290. $opt = array_merge($opt, CFComplexType::map(array(
  291. 'Dimensions' => $opt['Dimensions']
  292. ), 'member'));
  293. unset($opt['Dimensions']);
  294. }
  295. return $this->authenticate('ListMetrics', $opt, $this->hostname);
  296. }
  297. /**
  298. *
  299. * Gets statistics for the specified metric.
  300. *
  301. * The maximum number of data points returned from a single <code>GetMetricStatistics</code> request is 1,440. If a request is made that
  302. * generates more than 1,440 data points, Amazon CloudWatch returns an error. In such a case, alter the request by narrowing the specified time
  303. * range or increasing the specified period. Alternatively, make multiple requests across adjacent time ranges.
  304. *
  305. * Amazon CloudWatch aggregates data points based on the length of the <code>period</code> that you specify. For example, if you request
  306. * statistics with a one-minute granularity, Amazon CloudWatch aggregates data points with time stamps that fall within the same one-minute
  307. * period. In such a case, the data points queried can greatly outnumber the data points returned.
  308. *
  309. * The maximum number of data points that can be queried is 50,850; whereas the maximum number of data points returned is 1,440.
  310. *
  311. * The following examples show various statistics allowed by the data point query maximum of 50,850 when you call
  312. * <code>GetMetricStatistics</code> on Amazon EC2 instances with detailed (one-minute) monitoring enabled:
  313. *
  314. * <ul> <li>Statistics for up to 400 instances for a span of one hour</li>
  315. *
  316. * <li>Statistics for up to 35 instances over a span of 24 hours</li>
  317. *
  318. * <li>Statistics for up to 2 instances over a span of 2 weeks</li>
  319. *
  320. * </ul>
  321. *
  322. * @param string $namespace (Required) The namespace of the metric.
  323. * @param string $metric_name (Required) The name of the metric.
  324. * @param string $start_time (Required) The time stamp to use for determining the first datapoint to return. The value specified is inclusive; results include datapoints with the time stamp specified. The specified start time is rounded down to the nearest value. Datapoints are returned for start times up to two weeks in the past. Specified start times that are more than two weeks in the past will not return datapoints for metrics that are older than two weeks. Accepts any value that <php:strtotime()> understands.
  325. * @param string $end_time (Required) The time stamp to use for determining the last datapoint to return. The value specified is exclusive; results will include datapoints up to the time stamp specified. Accepts any value that <php:strtotime()> understands.
  326. * @param integer $period (Required) The granularity, in seconds, of the returned datapoints. <code>Period</code> must be at least 60 seconds and must be a multiple of 60. The default value is 60.
  327. * @param string|array $statistics (Required) The metric statistics to return. Pass a string for a single value, or an indexed array for multiple values.
  328. * @param string $unit (Required) The unit for the metric. [Allowed values: <code>Seconds</code>, <code>Microseconds</code>, <code>Milliseconds</code>, <code>Bytes</code>, <code>Kilobytes</code>, <code>Megabytes</code>, <code>Gigabytes</code>, <code>Terabytes</code>, <code>Bits</code>, <code>Kilobits</code>, <code>Megabits</code>, <code>Gigabits</code>, <code>Terabits</code>, <code>Percent</code>, <code>Count</code>, <code>Bytes/Second</code>, <code>Kilobytes/Second</code>, <code>Megabytes/Second</code>, <code>Gigabytes/Second</code>, <code>Terabytes/Second</code>, <code>Bits/Second</code>, <code>Kilobits/Second</code>, <code>Megabits/Second</code>, <code>Gigabits/Second</code>, <code>Terabits/Second</code>, <code>Count/Second</code>, <code>None</code>]
  329. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  330. * <li><code>Dimensions</code> - <code>array</code> - Optional - A list of dimensions describing qualities of the metric. <ul>
  331. * <li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
  332. * <li><code>Name</code> - <code>string</code> - Required - The name of the dimension. </li>
  333. * <li><code>Value</code> - <code>string</code> - Required - The value representing the dimension measurement </li>
  334. * </ul></li>
  335. * </ul></li>
  336. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  337. * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
  338. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  339. */
  340. public function get_metric_statistics($namespace, $metric_name, $start_time, $end_time, $period, $statistics, $unit, $opt = null)
  341. {
  342. if (!$opt) $opt = array();
  343. $opt['Namespace'] = $namespace;
  344. $opt['MetricName'] = $metric_name;
  345. // Optional parameter
  346. if (isset($opt['Dimensions']))
  347. {
  348. $opt = array_merge($opt, CFComplexType::map(array(
  349. 'Dimensions' => $opt['Dimensions']
  350. ), 'member'));
  351. unset($opt['Dimensions']);
  352. }
  353. $opt['StartTime'] = $this->util->convert_date_to_iso8601($start_time);
  354. $opt['EndTime'] = $this->util->convert_date_to_iso8601($end_time);
  355. $opt['Period'] = $period;
  356. // Required parameter
  357. $opt = array_merge($opt, CFComplexType::map(array(
  358. 'Statistics' => (is_array($statistics) ? $statistics : array($statistics))
  359. ), 'member'));
  360. $opt['Unit'] = $unit;
  361. return $this->authenticate('GetMetricStatistics', $opt, $this->hostname);
  362. }
  363. /**
  364. *
  365. * Disables actions for the specified alarms. When an alarm's actions are disabled the alarm's state may change, but none of the alarm's
  366. * actions will execute.
  367. *
  368. * @param string|array $alarm_names (Required) The names of the alarms to disable actions for. Pass a string for a single value, or an indexed array for multiple values.
  369. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  370. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  371. * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
  372. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  373. */
  374. public function disable_alarm_actions($alarm_names, $opt = null)
  375. {
  376. if (!$opt) $opt = array();
  377. // Required parameter
  378. $opt = array_merge($opt, CFComplexType::map(array(
  379. 'AlarmNames' => (is_array($alarm_names) ? $alarm_names : array($alarm_names))
  380. ), 'member'));
  381. return $this->authenticate('DisableAlarmActions', $opt, $this->hostname);
  382. }
  383. /**
  384. *
  385. * Retrieves alarms with the specified names. If no name is specified, all alarms for the user are returned. Alarms can be retrieved by using
  386. * only a prefix for the alarm name, the alarm state, or a prefix for any action.
  387. *
  388. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  389. * <li><code>AlarmNames</code> - <code>string|array</code> - Optional - A list of alarm names to retrieve information for. Pass a string for a single value, or an indexed array for multiple values. </li>
  390. * <li><code>AlarmNamePrefix</code> - <code>string</code> - Optional - The alarm name prefix. <code>AlarmNames</code> cannot be specified if this parameter is specified. </li>
  391. * <li><code>StateValue</code> - <code>string</code> - Optional - The state value to be used in matching alarms. [Allowed values: <code>OK</code>, <code>ALARM</code>, <code>INSUFFICIENT_DATA</code>]</li>
  392. * <li><code>ActionPrefix</code> - <code>string</code> - Optional - The action name prefix. </li>
  393. * <li><code>MaxRecords</code> - <code>integer</code> - Optional - The maximum number of alarm descriptions to retrieve. </li>
  394. * <li><code>NextToken</code> - <code>string</code> - Optional - The token returned by a previous call to indicate that there is more data available. </li>
  395. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  396. * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
  397. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  398. */
  399. public function describe_alarms($opt = null)
  400. {
  401. if (!$opt) $opt = array();
  402. // Optional parameter
  403. if (isset($opt['AlarmNames']))
  404. {
  405. $opt = array_merge($opt, CFComplexType::map(array(
  406. 'AlarmNames' => (is_array($opt['AlarmNames']) ? $opt['AlarmNames'] : array($opt['AlarmNames']))
  407. ), 'member'));
  408. unset($opt['AlarmNames']);
  409. }
  410. return $this->authenticate('DescribeAlarms', $opt, $this->hostname);
  411. }
  412. /**
  413. *
  414. * Retrieves all alarms for a single metric. Specify a statistic, period, or unit to filter the set of alarms further.
  415. *
  416. * @param string $metric_name (Required) The name of the metric.
  417. * @param string $namespace (Required) The namespace of the metric.
  418. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  419. * <li><code>Statistic</code> - <code>string</code> - Optional - The statistic for the metric. [Allowed values: <code>SampleCount</code>, <code>Average</code>, <code>Sum</code>, <code>Minimum</code>, <code>Maximum</code>]</li>
  420. * <li><code>Dimensions</code> - <code>array</code> - Optional - The list of dimensions associated with the metric. <ul>
  421. * <li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
  422. * <li><code>Name</code> - <code>string</code> - Required - The name of the dimension. </li>
  423. * <li><code>Value</code> - <code>string</code> - Required - The value representing the dimension measurement </li>
  424. * </ul></li>
  425. * </ul></li>
  426. * <li><code>Period</code> - <code>integer</code> - Optional - The period in seconds over which the statistic is applied. </li>
  427. * <li><code>Unit</code> - <code>string</code> - Optional - The unit for the metric. [Allowed values: <code>Seconds</code>, <code>Microseconds</code>, <code>Milliseconds</code>, <code>Bytes</code>, <code>Kilobytes</code>, <code>Megabytes</code>, <code>Gigabytes</code>, <code>Terabytes</code>, <code>Bits</code>, <code>Kilobits</code>, <code>Megabits</code>, <code>Gigabits</code>, <code>Terabits</code>, <code>Percent</code>, <code>Count</code>, <code>Bytes/Second</code>, <code>Kilobytes/Second</code>, <code>Megabytes/Second</code>, <code>Gigabytes/Second</code>, <code>Terabytes/Second</code>, <code>Bits/Second</code>, <code>Kilobits/Second</code>, <code>Megabits/Second</code>, <code>Gigabits/Second</code>, <code>Terabits/Second</code>, <code>Count/Second</code>, <code>None</code>]</li>
  428. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  429. * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
  430. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  431. */
  432. public function describe_alarms_for_metric($metric_name, $namespace, $opt = null)
  433. {
  434. if (!$opt) $opt = array();
  435. $opt['MetricName'] = $metric_name;
  436. $opt['Namespace'] = $namespace;
  437. // Optional parameter
  438. if (isset($opt['Dimensions']))
  439. {
  440. $opt = array_merge($opt, CFComplexType::map(array(
  441. 'Dimensions' => $opt['Dimensions']
  442. ), 'member'));
  443. unset($opt['Dimensions']);
  444. }
  445. return $this->authenticate('DescribeAlarmsForMetric', $opt, $this->hostname);
  446. }
  447. /**
  448. *
  449. * Retrieves history for the specified alarm. Filter alarms by date range or item type. If an alarm name is not specified, Amazon CloudWatch
  450. * returns histories for all of the owner's alarms.
  451. *
  452. * Amazon CloudWatch retains the history of an alarm for two weeks, whether or not you delete the alarm.
  453. *
  454. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  455. * <li><code>AlarmName</code> - <code>string</code> - Optional - The name of the alarm. </li>
  456. * <li><code>HistoryItemType</code> - <code>string</code> - Optional - The type of alarm histories to retrieve. [Allowed values: <code>ConfigurationUpdate</code>, <code>StateUpdate</code>, <code>Action</code>]</li>
  457. * <li><code>StartDate</code> - <code>string</code> - Optional - The starting date to retrieve alarm history. May be passed as a number of seconds since UNIX Epoch, or any string compatible with <php:strtotime()>.</li>
  458. * <li><code>EndDate</code> - <code>string</code> - Optional - The ending date to retrieve alarm history. May be passed as a number of seconds since UNIX Epoch, or any string compatible with <php:strtotime()>.</li>
  459. * <li><code>MaxRecords</code> - <code>integer</code> - Optional - The maximum number of alarm history records to retrieve. </li>
  460. * <li><code>NextToken</code> - <code>string</code> - Optional - The token returned by a previous call to indicate that there is more data available. </li>
  461. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  462. * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
  463. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  464. */
  465. public function describe_alarm_history($opt = null)
  466. {
  467. if (!$opt) $opt = array();
  468. // Optional parameter
  469. if (isset($opt['StartDate']))
  470. {
  471. $opt['StartDate'] = $this->util->convert_date_to_iso8601($opt['StartDate']);
  472. }
  473. // Optional parameter
  474. if (isset($opt['EndDate']))
  475. {
  476. $opt['EndDate'] = $this->util->convert_date_to_iso8601($opt['EndDate']);
  477. }
  478. return $this->authenticate('DescribeAlarmHistory', $opt, $this->hostname);
  479. }
  480. /**
  481. *
  482. * Enables actions for the specified alarms.
  483. *
  484. * @param string|array $alarm_names (Required) The names of the alarms to enable actions for. Pass a string for a single value, or an indexed array for multiple values.
  485. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  486. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  487. * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
  488. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  489. */
  490. public function enable_alarm_actions($alarm_names, $opt = null)
  491. {
  492. if (!$opt) $opt = array();
  493. // Required parameter
  494. $opt = array_merge($opt, CFComplexType::map(array(
  495. 'AlarmNames' => (is_array($alarm_names) ? $alarm_names : array($alarm_names))
  496. ), 'member'));
  497. return $this->authenticate('EnableAlarmActions', $opt, $this->hostname);
  498. }
  499. /**
  500. *
  501. * Deletes all specified alarms. In the event of an error, no alarms are deleted.
  502. *
  503. * @param string|array $alarm_names (Required) A list of alarms to be deleted. Pass a string for a single value, or an indexed array for multiple values.
  504. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  505. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  506. * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
  507. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  508. */
  509. public function delete_alarms($alarm_names, $opt = null)
  510. {
  511. if (!$opt) $opt = array();
  512. // Required parameter
  513. $opt = array_merge($opt, CFComplexType::map(array(
  514. 'AlarmNames' => (is_array($alarm_names) ? $alarm_names : array($alarm_names))
  515. ), 'member'));
  516. return $this->authenticate('DeleteAlarms', $opt, $this->hostname);
  517. }
  518. /**
  519. *
  520. * Temporarily sets the state of an alarm. When the updated <code>StateValue</code> differs from the previous value, the action configured for
  521. * the appropriate state is invoked. This is not a permanent change. The next periodic alarm check (in about a minute) will set the alarm to
  522. * its actual state.
  523. *
  524. * @param string $alarm_name (Required) The descriptive name for the alarm. This name must be unique within the user's AWS account. The maximum length is 255 characters.
  525. * @param string $state_value (Required) The value of the state. [Allowed values: <code>OK</code>, <code>ALARM</code>, <code>INSUFFICIENT_DATA</code>]
  526. * @param string $state_reason (Required) The reason that this alarm is set to this specific state (in human-readable text format)
  527. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  528. * <li><code>StateReasonData</code> - <code>string</code> - Optional - The reason that this alarm is set to this specific state (in machine-readable JSON format) </li>
  529. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  530. * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
  531. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  532. */
  533. public function set_alarm_state($alarm_name, $state_value, $state_reason, $opt = null)
  534. {
  535. if (!$opt) $opt = array();
  536. $opt['AlarmName'] = $alarm_name;
  537. $opt['StateValue'] = $state_value;
  538. $opt['StateReason'] = $state_reason;
  539. return $this->authenticate('SetAlarmState', $opt, $this->hostname);
  540. }
  541. }
  542. /*%******************************************************************************************%*/
  543. // EXCEPTIONS
  544. /**
  545. * Default CloudWatch Exception.
  546. */
  547. class CloudWatch_Exception extends Exception {}