/**
  * @covers Aws\CloudWatch\CloudWatchClient::factory
  */
 public function testFactoryInitializesClient()
 {
     $client = CloudWatchClient::factory(array('key' => 'foo', 'secret' => 'bar', 'region' => 'us-west-2'));
     $this->assertInstanceOf('Aws\\Common\\Signature\\SignatureV2', $client->getSignature());
     $this->assertInstanceOf('Aws\\Common\\Credentials\\Credentials', $client->getCredentials());
     $this->assertEquals('https://monitoring.us-west-2.amazonaws.com', $client->getBaseUrl());
 }
Пример #2
0
function getCloudWatchClient($conf)
{
    if (isset($conf->aws->profil)) {
        return CloudWatchClient::factory(array('profil' => $conf->aws->profil, 'region' => $conf->aws->region, 'version' => '2010-08-01'));
    }
    return CloudWatchClient::factory(array('credentials' => array('key' => $conf->aws->key, 'secret' => $conf->aws->secret), 'region' => $conf->aws->region, 'version' => '2010-08-01'));
}
 /**
  * @param CollectorAccessInterface $collector
  * @return int
  */
 public function requestValue(CollectorAccessInterface $collector)
 {
     $metric = $collector->getMetric();
     $identifier = isset($metric['identifier']) ? $metric['identifier'] : null;
     $container = MonolistWatcherBundle::getContainer();
     $awsConfig = $container->getParameter('aws');
     if ($awsConfig['enabled'] == false) {
         return null;
         //TODO write to log or handle it on another way
     }
     $client = CloudWatchClient::factory(array('key' => $awsConfig['access_key'], 'secret' => $awsConfig['secret_key'], 'region' => 'eu-west-1'));
     $result = $client->getMetricStatistics(array('Namespace' => 'AWS/ELB', 'MetricName' => 'UnHealthyHostCount', 'Dimensions' => array(array('Name' => 'LoadBalancerName', 'Value' => $identifier)), 'StartTime' => strtotime('-2 min'), 'EndTime' => strtotime('now'), 'Period' => 60, 'Statistics' => array('Maximum', 'Minimum')));
     $resultArray = $result->get('Datapoints');
     $lastResult = empty($resultArray) ? null : array_pop($resultArray);
     return intval($lastResult['Maximum']);
 }
Пример #4
0
 private function getCloudWatchClient()
 {
     return CloudWatchClient::factory($this->getConnectionOptions());
 }
 /**
  * @param array $config
  *
  * @return array
  */
 protected function getCpuUtilization($config)
 {
     $client = CloudWatchClient::factory(['key' => $config['key'], 'secret' => $config['secret'], 'region' => $config['region']]);
     $result = $client->getMetricStatistics(['Namespace' => 'AWS/EC2', 'MetricName' => 'CPUUtilization', 'Dimensions' => [['Name' => $config['dimension_name'], 'Value' => $config['dimension_value']]], 'StartTime' => strtotime($config['begin']), 'EndTime' => strtotime('now'), 'Period' => 900, 'Statistics' => ['Average']]);
     $result = $result->toArray();
     $data = [];
     foreach ($result['Datapoints'] as $row) {
         $data[] = ['x' => (strtotime($row['Timestamp']) + 7200) * 1000, 'y' => round($row['Average'], 3)];
     }
     usort($data, function ($first, $second) {
         if ($first['x'] > $second['x']) {
             return 1;
         }
         return $first['x'] == $second['x'] ? 0 : -1;
     });
     return ['chart.html.twig', ['data' => $data, 'name' => $config['environment'] . ' - CPU']];
 }
Пример #6
0
 public function __construct()
 {
     parent::__construct();
     $this->cloud_watch_client = CloudWatchClient::factory(['region' => 'us-east-1']);
 }