mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 16:58:46 -03:30
Merge pull request #4372 from ryanpetrello/instance-metrics-hostname
include instance hostnames in metrics endpoint Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
@@ -160,7 +160,7 @@ def _get_isolated_datetime(last_check):
|
|||||||
|
|
||||||
|
|
||||||
@register('instance_info')
|
@register('instance_info')
|
||||||
def instance_info(since):
|
def instance_info(since, include_hostnames=False):
|
||||||
info = {}
|
info = {}
|
||||||
instances = models.Instance.objects.values_list('hostname').values(
|
instances = models.Instance.objects.values_list('hostname').values(
|
||||||
'uuid', 'version', 'capacity', 'cpu', 'memory', 'managed_by_policy', 'hostname', 'last_isolated_check', 'enabled')
|
'uuid', 'version', 'capacity', 'cpu', 'memory', 'managed_by_policy', 'hostname', 'last_isolated_check', 'enabled')
|
||||||
@@ -175,6 +175,8 @@ def instance_info(since):
|
|||||||
'last_isolated_check': _get_isolated_datetime(instance['last_isolated_check']),
|
'last_isolated_check': _get_isolated_datetime(instance['last_isolated_check']),
|
||||||
'enabled': instance['enabled']
|
'enabled': instance['enabled']
|
||||||
}
|
}
|
||||||
|
if include_hostnames is True:
|
||||||
|
instance_info['hostname'] = instance['hostname']
|
||||||
info[instance['uuid']] = instance_info
|
info[instance['uuid']] = instance_info
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ USER_SESSIONS = Gauge('awx_sessions_total', 'Number of sessions', ['type',])
|
|||||||
CUSTOM_VENVS = Gauge('awx_custom_virtualenvs_total', 'Number of virtualenvs')
|
CUSTOM_VENVS = Gauge('awx_custom_virtualenvs_total', 'Number of virtualenvs')
|
||||||
RUNNING_JOBS = Gauge('awx_running_jobs_total', 'Number of running jobs on the Tower system')
|
RUNNING_JOBS = Gauge('awx_running_jobs_total', 'Number of running jobs on the Tower system')
|
||||||
|
|
||||||
INSTANCE_CAPACITY = Gauge('awx_instance_capacity', 'Capacity of each node in a Tower system', ['instance_uuid',])
|
INSTANCE_CAPACITY = Gauge('awx_instance_capacity', 'Capacity of each node in a Tower system', ['hostname', 'instance_uuid',])
|
||||||
INSTANCE_CPU = Gauge('awx_instance_cpu', 'CPU cores on each node in a Tower system', ['instance_uuid',])
|
INSTANCE_CPU = Gauge('awx_instance_cpu', 'CPU cores on each node in a Tower system', ['hostname', 'instance_uuid',])
|
||||||
INSTANCE_MEMORY = Gauge('awx_instance_memory', 'RAM (Kb) on each node in a Tower system', ['instance_uuid',])
|
INSTANCE_MEMORY = Gauge('awx_instance_memory', 'RAM (Kb) on each node in a Tower system', ['hostname', 'instance_uuid',])
|
||||||
INSTANCE_INFO = Info('awx_instance', 'Info about each node in a Tower system', ['instance_uuid',])
|
INSTANCE_INFO = Info('awx_instance', 'Info about each node in a Tower system', ['hostname', 'instance_uuid',])
|
||||||
INSTANCE_LAUNCH_TYPE = Gauge('awx_instance_launch_type_total', 'Type of Job launched', ['node', 'launch_type',])
|
INSTANCE_LAUNCH_TYPE = Gauge('awx_instance_launch_type_total', 'Type of Job launched', ['node', 'launch_type',])
|
||||||
INSTANCE_STATUS = Gauge('awx_instance_status_total', 'Status of Job launched', ['node', 'status',])
|
INSTANCE_STATUS = Gauge('awx_instance_status_total', 'Status of Job launched', ['node', 'status',])
|
||||||
|
|
||||||
@@ -89,13 +89,13 @@ def metrics():
|
|||||||
|
|
||||||
RUNNING_JOBS.set(current_counts['running_jobs'])
|
RUNNING_JOBS.set(current_counts['running_jobs'])
|
||||||
|
|
||||||
|
instance_data = instance_info(None, include_hostnames=True)
|
||||||
instance_data = instance_info(None)
|
for uuid, info in instance_data.items():
|
||||||
for uuid in instance_data:
|
hostname = info['hostname']
|
||||||
INSTANCE_CAPACITY.labels(instance_uuid=uuid).set(instance_data[uuid]['capacity'])
|
INSTANCE_CAPACITY.labels(hostname=hostname, instance_uuid=uuid).set(instance_data[uuid]['capacity'])
|
||||||
INSTANCE_CPU.labels(instance_uuid=uuid).set(instance_data[uuid]['cpu'])
|
INSTANCE_CPU.labels(hostname=hostname, instance_uuid=uuid).set(instance_data[uuid]['cpu'])
|
||||||
INSTANCE_MEMORY.labels(instance_uuid=uuid).set(instance_data[uuid]['memory'])
|
INSTANCE_MEMORY.labels(hostname=hostname, instance_uuid=uuid).set(instance_data[uuid]['memory'])
|
||||||
INSTANCE_INFO.labels(instance_uuid=uuid).info({
|
INSTANCE_INFO.labels(hostname=hostname, instance_uuid=uuid).info({
|
||||||
'enabled': str(instance_data[uuid]['enabled']),
|
'enabled': str(instance_data[uuid]['enabled']),
|
||||||
'last_isolated_check': getattr(instance_data[uuid], 'last_isolated_check', 'None'),
|
'last_isolated_check': getattr(instance_data[uuid], 'last_isolated_check', 'None'),
|
||||||
'managed_by_policy': str(instance_data[uuid]['managed_by_policy']),
|
'managed_by_policy': str(instance_data[uuid]['managed_by_policy']),
|
||||||
|
|||||||
Reference in New Issue
Block a user