Last active
June 23, 2017 04:01
-
-
Save masayuki5160/c57f10f5d4497b8b40f1 to your computer and use it in GitHub Desktop.
AWS SDK For PHPをつかってCloudWatch APIへアクセス
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Include the SDK using the Composer autoloader | |
| require 'vendor/autoload.php'; | |
| use Aws\CloudWatch\CloudWatchClient; | |
| $client = CloudWatchClient::factory(array( | |
| 'key' => 'keyをね', | |
| 'secret' => '秘密のやつをここに', | |
| 'region' => 'ap-northeast-1' | |
| )); | |
| $dimensions = array( | |
| array('Name' => 'InstanceId', 'Value' => 'i-hogehoge(コンソールにのってるID)'),// HOGE SERVER | |
| array('Name' => 'InstanceId', 'Value' => 'i-hogehoge(コンソールにのってるID)'),// HOGEHOGE SERVER | |
| ); | |
| $result = $client->getMetricStatistics(array( | |
| 'Namespace' => 'AWS/EC2', | |
| 'MetricName' => 'CPUUtilization', | |
| 'Dimensions' => $dimensions, | |
| 'StartTime' => strtotime('-1 days'), | |
| 'EndTime' => strtotime('now'), | |
| 'Period' => 3000, | |
| 'Statistics' => array('Maximum', 'Minimum','Average'), | |
| )); | |
| var_dump($result); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ pwd | |
| /home/ec2-user/aws-php-sample | |
| $ php cloudwatch.php | |
| object(Guzzle\Service\Resource\Model)#79 (2) { | |
| ["structure":protected]=> | |
| NULL | |
| ["data":protected]=> | |
| array(3) { | |
| ["Datapoints"]=> | |
| array(29) { | |
| [0]=> | |
| array(5) { | |
| ["Timestamp"]=> | |
| string(20) "2014-05-25T03:49:00Z" | |
| ["Unit"]=> | |
| string(7) "Percent" | |
| ["Minimum"]=> | |
| string(3) "0.0" | |
| ["Maximum"]=> | |
| string(4) "3.33" | |
| ["Average"]=> | |
| string(6) "1.2992" | |
| } | |
| [1]=> | |
| array(5) { | |
| ["Timestamp"]=> | |
| string(20) "2014-05-25T02:09:00Z" | |
| ["Unit"]=> | |
| string(7) "Percent" | |
| ["Minimum"]=> | |
| string(3) "0.0" | |
| ["Maximum"]=> | |
| string(4) "3.33" | |
| ["Average"]=> | |
| .... | |
| [28]=> | |
| array(5) { | |
| ["Timestamp"]=> | |
| string(20) "2014-05-24T21:59:00Z" | |
| ["Unit"]=> | |
| string(7) "Percent" | |
| ["Minimum"]=> | |
| string(3) "0.0" | |
| ["Maximum"]=> | |
| string(4) "3.33" | |
| ["Average"]=> | |
| string(6) "1.1998" | |
| } | |
| } | |
| ["Label"]=> | |
| string(14) "CPUUtilization" | |
| ["ResponseMetadata"]=> | |
| array(1) { | |
| ["RequestId"]=> | |
| string(36) "f7c2f31c-e403-11e3-85ff-1fb877523246" | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考サイト
->環境のセットアップ
http://aws.amazon.com/jp/developers/getting-started/php/
->CloudWatchについて
http://www.slideshare.net/ShinsukeYokota/cloudwatch-29076381