Thursday, December 17, 2015

<?php 
require 'vendor/autoload.php'; 

9 / 30
use Aws\CloudWatch\CloudWatchClient; 


$key = "Your_key"; 
$secret = "Your_secret"; 
$region = "us-west-2";
$version ="latest";


// Use the us-west-2 region and latest version of each client. 
$sharedConfig = [ 
   'region'  => $region, 
   'version' => $version, 
 'credentials' => array( 
   'key' => $key, 
   'secret'  => $secret, 
 ), 
   'key'    => $key, 
   'secret' => $secret, 
]; 


// Create an SDK class used to share configuration across clients. 
$sdk = new Aws\Sdk($sharedConfig); 
$client = $sdk->createCloudWatch(); 


function grabber($client, $tablename, $metric) { 
 $output = array(); 
 $results = $client->getMetricStatistics(array( 
   'Namespace'  => 'AWS/ECS', 
   'MetricName' => $metric, 
   'Dimensions' => array( 
     array( 

10 / 30
       'Name' => 'TableName', 
       'Value' => $tablename, 
     ), 
   ), 
   'StartTime'  => strtotime('-1 days'), //'-'.$interval.' minutes'), 
   'EndTime'    => strtotime('now'), 
   'Period'     => 300, 
   'Statistics' => array('Minimum', 'Maximum', 'Average', 'Sum'), 
 )); 
 echo 'RESULTS='.serialize($results); 
print "-------------------------------------------\n"; 
 print "    $metric\n"; 
 print "-------------------------------------------\n"; 
 foreach ($results as $result){ 
 echo 'RESULT='.serialize($result); 
 if (is_array($result) && array_key_exists('Datapoints', $result)){ 
 foreach ( $result['Datapoints'] as $item ) { 
   $min = $item['Minimum']; 
   $max = $item['Maximum']; 
   $avg = $item['Average']; 
   $sum = $item['Sum']; 
   $time = $item['Timestamp']; 
   print "$time -- min $min, max $max, avg $avg, sum $sum\n"; 
   array_push($output, array('key'=>$time, 'min'=>$min, 'max'=>$max, 'avg'=>$avg,'sum'=>$sum, 'cumulate'=>true, 'units'=>'count')); 
 } 
 } 
 } 
 return $output; 



To detect whether a rectangle of contiguous 1 or zero exists and if so, it's size given the starting position of top left corner as the element in a 2d array of 1 and 0, we use the following:

starting at this point as top left, we walk the rectangle based on increasing diagonal or side bottom or right and making sure all newly encountered elements within the new bounds are of similar value.

No comments:

Post a Comment