Permalink
Browse files

Some fixes to sensor de and sensor gathering

  • Loading branch information...
1 parent b00e982 commit 7d71d954d647ec0158b89eea19e9f334dd1495ad @oldpatricka oldpatricka committed Nov 16, 2012
Showing with 14 additions and 5 deletions.
  1. +9 −3 epu/decisionengine/impls/sensor.py
  2. +5 −2 epu/epumanagement/decider.py
@@ -220,17 +220,20 @@ def decide(self, control, state):
# Check Sensors
cooldown = timedelta(seconds=self.cooldown_period)
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
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,7 +246,10 @@ 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")
scale_by = 0
@@ -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,18 @@ 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():
+ if iaas_id != instance.iaas_id:
+ continue
series = metric.get(Statistics.SERIES)
if series is not None and series != []:
sensor_state[instance.instance_id] = metric
- domain.new_instance_sensor(instance.instance_id, sensor_state)
+ if 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 7d71d95

Please sign in to comment.