function getScalingDecision()
{
$algo = Scalr_Scaling_Algorithm::get($this->getMetric()->algorithm);
$sensor = Scalr_Scaling_Sensor::get($this->getMetric()->alias);
$dbFarmRole = DBFarmRole::LoadByID($this->farmRoleId);
if ($sensor) {
try {
$sensorValue = $sensor->getValue($dbFarmRole, $this);
} catch (Exception $e) {
$this->logger->warn(new FarmLogMessage($dbFarmRole->FarmID, sprintf("Unable to read Scaling Metric value: %s", $e->getMessage())));
return Scalr_Scaling_Decision::NOOP;
}
$this->logger->info(sprintf(_("Raw sensor value (id: %s, metric_id: %s, metric name: %s): %s"), $this->id, $this->metricId, $this->getMetric()->name, serialize($sensorValue)));
switch ($this->getMetric()->calcFunction) {
default:
$value = $sensorValue[0];
break;
case "avg":
$value = count($sensorValue) != 0 ? @array_sum($sensorValue) / count($sensorValue) : 0;
break;
case "sum":
$value = @array_sum($sensorValue);
break;
}
$this->lastValue = round($value, 5);
$this->save();
$invert = $sensor->isInvert;
} else {
$invert = false;
}
return $algo->makeDecision($dbFarmRole, $this, $invert);
}