Permalink
Browse files

Some fixes as a result of using sensor DE with phantom.

  • Loading branch information...
1 parent d3159e4 commit 24daee8ec586a56aae2fbc2af62df6b856e78bbd @oldpatricka oldpatricka committed Nov 17, 2012
Showing with 21 additions and 11 deletions.
  1. +12 −6 epu/decisionengine/impls/sensor.py
  2. +9 −5 epu/epumanagement/decider.py
@@ -222,15 +222,17 @@ def decide(self, control, state):
time_since_last_action = datetime.now() - self.time_of_last_scale_action
if time_since_last_action < cooldown:
log.debug("No scaling action, in cooldown period")
- scale_by = 0
+ return
elif self.metric is not None and self.sample_function is not None:
values = []
for instance_id in valid_set:
instance = state.instances[instance_id]
- if hasattr(instance, 'sensor_data') and instance.sensor_data:
+ if (hasattr(instance, 'sensor_data') and instance.sensor_data and
+ instance.sensor_data.get(self.sample_function)):
values.append(instance.sensor_data[self.sample_function])
try:
- average_metric = float(sum(values)) / float(len(values))
+ divisor = max(len(values), valid_count)
+ average_metric = float(sum(values)) / float(divisor)
except ZeroDivisionError:
average_metric = None
@@ -243,9 +245,12 @@ def decide(self, control, state):
else:
scale_by = 0
- self.time_of_last_scale_action = datetime.now()
+ if scale_by != 0:
+ self.time_of_last_scale_action = datetime.now()
+
+
else:
- log.debug("No sensor metric or sample function specified. Not scaling")
+ # No sensor metric or sample function specified. Not scaling
scale_by = 0
wanted_target = valid_count + scale_by
@@ -313,7 +318,8 @@ def _launch_one(self, control, extravars=None):
log.info("Launched an instance ('%s')", instance_ids[0])
def _destroy_one(self, control, instanceid):
- control.destroy_instances([instanceid])
+ owner = control.domain.owner
+ control.destroy_instances([instanceid], caller=owner)
log.info("Destroyed an instance ('%s')" % instanceid)
def reconfigure(self, control, newconf):
@@ -214,7 +214,6 @@ def _get_engine_sensor_state(self, domain):
end_time = datetime.utcnow()
start_time = end_time - timedelta(seconds=sample_period)
- sensor_state = {}
instances = domain.get_instances()
for instance in instances:
if 'ec2' not in instance.site and sensor_type == CLOUDWATCH_SENSOR_TYPE:
@@ -231,14 +230,19 @@ def _get_engine_sensor_state(self, domain):
continue
dimensions = {'InstanceId': instance.iaas_id}
+ sensor_state = {}
state = sensor_aggregator.get_metric_statistics(period, start_time,
end_time, metric, sample_function, dimensions)
- for iaas_id, metric in state.iteritems():
- series = metric.get(Statistics.SERIES)
+ for iaas_id, metric_result in state.iteritems():
+ if iaas_id != instance.iaas_id:
+ continue
+ series = metric_result.get(Statistics.SERIES)
if series is not None and series != []:
- sensor_state[instance.instance_id] = metric
+ sensor_state[instance.instance_id] = metric_result
+
+ if sensor_state != {}:
+ domain.new_instance_sensor(instance.instance_id, sensor_state)
- domain.new_instance_sensor(instance.instance_id, sensor_state)
def _get_sensor_aggregator(self, config):
sensor_type = config.get(CONF_SENSOR_TYPE)

0 comments on commit 24daee8

Please sign in to comment.