Skip to content

Commit

Permalink
Merge pull request #4 from AlanCoding/elijah_metrics
Browse files Browse the repository at this point in the history
Minor changes to instance loop structure
  • Loading branch information
kdelee authored Aug 29, 2022
2 parents 125801e + 2437a84 commit d3f15f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 4 additions & 4 deletions awx/main/analytics/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def instance_info(since, include_hostnames=False, **kwargs):
# Use same method that the TaskManager does to compute consumed capacity without querying all running jobs for each Instance
active_tasks = models.UnifiedJob.objects.filter(status__in=['running', 'waiting']).only('task_impact', 'controller_node', 'execution_node')
tm_instances = TaskManagerInstances(active_tasks, instance_fields=['uuid', 'version', 'capacity', 'cpu', 'memory', 'managed_by_policy', 'enabled'])
for instance in tm_instances.instance_objects:
consumed_capacity = tm_instances[instance.hostname].consumed_capacity
for tm_instance in tm_instances.instances_by_hostname.values():
instance = tm_instance.obj
instance_info = {
'uuid': instance.uuid,
'version': instance.version,
Expand All @@ -249,8 +249,8 @@ def instance_info(since, include_hostnames=False, **kwargs):
'memory': instance.memory,
'managed_by_policy': instance.managed_by_policy,
'enabled': instance.enabled,
'consumed_capacity': consumed_capacity,
'remaining_capacity': instance.capacity - consumed_capacity,
'consumed_capacity': tm_instance.consumed_capacity,
'remaining_capacity': instance.capacity - tm_instance.consumed_capacity,
}
if include_hostnames is True:
instance_info['hostname'] = instance.hostname
Expand Down
4 changes: 1 addition & 3 deletions awx/main/scheduler/task_manager_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ def remaining_capacity(self):


class TaskManagerInstances:
def __init__(self, active_tasks, instances=None, instance_fields=['node_type', 'capacity', 'hostname', 'enabled']):
def __init__(self, active_tasks, instances=None, instance_fields=('node_type', 'capacity', 'hostname', 'enabled')):
self.instances_by_hostname = dict()
self.instance_objects = []
if instances is None:
instances = Instance.objects.filter(hostname__isnull=False, enabled=True).exclude(node_type='hop').only(*instance_fields)
for instance in instances:
self.instances_by_hostname[instance.hostname] = TaskManagerInstance(instance)
self.instance_objects.append(instance)

# initialize remaining capacity based on currently waiting and running tasks
for task in active_tasks:
Expand Down

0 comments on commit d3f15f5

Please sign in to comment.