IAMロールを使用してお客様のアカウントのログを監視するツールに使用するため、
cloudwatch のカスタムメトリクスをAWS SDK for PHP で取得したいです。
下記のようにputMetricDataを送信しましたが、うまくできませんでした。
権限はfullでつけています。
php
1$client = CloudWatchClient::factory(array( 2 'version'=> 'latest', 3 'region' => $region_code, 4 'credentials' => array( 5 'key' => $AccessKeyId, 6 'secret' => $SecretAccessKey, 7 'token' => $SessionToken 8 ) 9 )); 10 11 $result = $client->putMetricData(array( 12 'Namespace' => 'System/Linux', 13 'MetricData' => array( 14 array( 15 'MetricName' => 'MemoryUtilization', 16 'Timestamp' => time(), 17 'Value' => 0, 18 'Unit' => 'Percent' 19 ) 20 ) 21 )); 22 23ーーーーーーPUTして返ってきた結果ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー 24Data can be retrieved from the model object using the get() method of the 25model (e.g., `$result->get($key)`) or "accessing the result like an 26associative array (e.g. `$result['key']`). You can also execute JMESPath 27expressions on the result data using the search() method. 28 29{ 30 "@metadata": { 31 "statusCode": 200, 32 "effectiveUri": "https://monitoring.sa-east-1.amazonaws.com", 33 "headers": { 34 "x-amzn-requestid": "************************************", 35 "content-type": "text/xml", 36 "content-length": "212", 37 "date": "Sat, 03 Nov 2018 03:05:57 GMT" 38 }, 39 "transferStats": { 40 "http": [ 41 [] 42 ] 43 } 44 } 45} 46 47---GETして返ってきた結果-------------------------------------------- 48{ 49 "Label": "MemoryUtilization", 50 "Datapoints": [], 51 "@metadata": { 52 "statusCode": 200, 53 "effectiveUri": "https://monitoring.sa-east-1.amazonaws.com", 54 "headers": { 55 "x-amzn-requestid": "******************************", 56 "content-type": "text/xml", 57 "content-length": "340", 58 "date": "Sat, 03 Nov 2018 04:20:48 GMT" 59 }, 60 "transferStats": { 61 "http": [ 62 [] 63 ] 64 } 65 } 66} 67 68 69getMetricStatisticsのコード 70 71//インスタンスIDをセット 72$dimensions = array(array('Name' => 'InstanceId', 'Value' => $InstanceId)); 73 74$result = $client->getMetricStatistics(array( 75 'Namespace' => $namespace, 76 'MetricName' => $metricName, 77 'Dimensions' => $dimensions, 78 'StartTime' => $StartTime, 79 'EndTime' => strtotime('now'), 80 'Period' => '3600', 81 'Statistics' => array('Maximum') 82 )); 83
回答1件
あなたの回答
tips
プレビュー