コード例 #1
0
 /**
  * @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']);
 }
コード例 #2
0
 /**
  * Save the entity to db
  *
  * @return void
  */
 public function save()
 {
     $container = MonolistWatcherBundle::getContainer();
     /** @var \Doctrine\Bundle\DoctrineBundle\Registry $doct */
     $doct = $container->get('doctrine');
     $em = $doct->getManager();
     $em->persist($this);
     $em->flush();
 }