/** * @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']); }
/** * Save collected data into db. * * @param CollectorAccessInterface $collectorAccessInterface * @return mixed */ public function saveCollectedData(CollectorAccessInterface $collectorAccessInterface) { $metric = $collectorAccessInterface->getMetric(); $this->setIdentifier($metric['identifier']); $this->setTimestamp($metric['timestamp']); $this->setValue($metric['value']); $this->save(); }