add uuids to ping and metrics

This commit is contained in:
Christian Adams
2019-04-10 15:40:35 -04:00
parent 23d0f6022c
commit 40393e201f
6 changed files with 12 additions and 13 deletions

View File

@@ -159,11 +159,12 @@ class ApiV1PingView(APIView):
'ha': is_ha_environment(), 'ha': is_ha_environment(),
'version': get_awx_version(), 'version': get_awx_version(),
'active_node': settings.CLUSTER_HOST_ID, 'active_node': settings.CLUSTER_HOST_ID,
'install_uuid': settings.INSTALL_UUID,
} }
response['instances'] = [] response['instances'] = []
for instance in Instance.objects.all(): for instance in Instance.objects.all():
response['instances'].append(dict(node=instance.hostname, heartbeat=instance.modified, response['instances'].append(dict(node=instance.hostname, uuid=instance.uuid, heartbeat=instance.modified,
capacity=instance.capacity, version=instance.version)) capacity=instance.capacity, version=instance.version))
sorted(response['instances'], key=operator.itemgetter('node')) sorted(response['instances'], key=operator.itemgetter('node'))
response['instance_groups'] = [] response['instance_groups'] = []

View File

@@ -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', ['type',]) INSTANCE_CAPACITY = Gauge('awx_instance_capacity', 'Capacity of each node in a Tower system', ['instance_uuid',])
INSTANCE_CPU = Gauge('awx_instance_cpu', 'CPU cores on each node in a Tower system', ['type',]) INSTANCE_CPU = Gauge('awx_instance_cpu', 'CPU cores on each node in a Tower system', ['instance_uuid',])
INSTANCE_MEMORY = Gauge('awx_instance_memory', 'RAM (Kb) on each node in a Tower system', ['type',]) INSTANCE_MEMORY = Gauge('awx_instance_memory', 'RAM (Kb) on each node in a Tower system', ['instance_uuid',])
INSTANCE_INFO = Info('awx_instance', 'Info about each node in a Tower system', ['type',]) INSTANCE_INFO = Info('awx_instance', 'Info about each node in a Tower system', ['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',])
@@ -48,7 +48,7 @@ INSTANCE_STATUS = Gauge('awx_instance_status_total', 'Status of Job launched', [
def metrics(): def metrics():
license_info = get_license(show_key=False) license_info = get_license(show_key=False)
SYSTEM_INFO.info({ SYSTEM_INFO.info({
'system_uuid': settings.SYSTEM_UUID, 'install_uuid': settings.INSTALL_UUID,
'insights_analytics': str(settings.INSIGHTS_DATA_ENABLED), 'insights_analytics': str(settings.INSIGHTS_DATA_ENABLED),
'tower_url_base': settings.TOWER_URL_BASE, 'tower_url_base': settings.TOWER_URL_BASE,
'tower_version': get_awx_version(), 'tower_version': get_awx_version(),
@@ -87,10 +87,10 @@ def metrics():
instance_data = instance_info(None) instance_data = instance_info(None)
for uuid in instance_data: for uuid in instance_data:
INSTANCE_CAPACITY.labels(type=uuid).set(instance_data[uuid]['capacity']) INSTANCE_CAPACITY.labels(instance_uuid=uuid).set(instance_data[uuid]['capacity'])
INSTANCE_CPU.labels(type=uuid).set(instance_data[uuid]['cpu']) INSTANCE_CPU.labels(instance_uuid=uuid).set(instance_data[uuid]['cpu'])
INSTANCE_MEMORY.labels(type=uuid).set(instance_data[uuid]['memory']) INSTANCE_MEMORY.labels(instance_uuid=uuid).set(instance_data[uuid]['memory'])
INSTANCE_INFO.labels(type=uuid).info({ INSTANCE_INFO.labels(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']),
@@ -100,7 +100,6 @@ def metrics():
instance_data = job_instance_counts(None) instance_data = job_instance_counts(None)
for node in instance_data: for node in instance_data:
# skipping internal execution node (for system jobs) # skipping internal execution node (for system jobs)
# TODO: determine if we should exclude execution_node from instance count
if node == '': if node == '':
continue continue
types = instance_data[node].get('launch_type', {}) types = instance_data[node].get('launch_type', {})

View File

@@ -60,7 +60,6 @@ def test_metrics_counts(organization_factory, job_template_factory, workflow_job
@pytest.mark.django_db @pytest.mark.django_db
def test_metrics_permissions(get, admin, org_admin, alice, bob, organization): def test_metrics_permissions(get, admin, org_admin, alice, bob, organization):
assert get(reverse('api:metrics_view'), user=admin).status_code == 200 assert get(reverse('api:metrics_view'), user=admin).status_code == 200
assert get(reverse('api:metrics_view'), user=org_admin).status_code == 403 assert get(reverse('api:metrics_view'), user=org_admin).status_code == 403
assert get(reverse('api:metrics_view'), user=alice).status_code == 403 assert get(reverse('api:metrics_view'), user=alice).status_code == 403
@@ -75,7 +74,6 @@ def test_metrics_permissions(get, admin, org_admin, alice, bob, organization):
@pytest.mark.django_db @pytest.mark.django_db
def test_metrics_http_methods(get, post, patch, put, options, admin): def test_metrics_http_methods(get, post, patch, put, options, admin):
assert get(reverse('api:metrics_view'), user=admin).status_code == 200 assert get(reverse('api:metrics_view'), user=admin).status_code == 200
assert put(reverse('api:metrics_view'), user=admin).status_code == 405 assert put(reverse('api:metrics_view'), user=admin).status_code == 405
assert patch(reverse('api:metrics_view'), user=admin).status_code == 405 assert patch(reverse('api:metrics_view'), user=admin).status_code == 405

View File

@@ -116,6 +116,7 @@ INSTALLED_APPS += ('rest_framework_swagger',)
# Configure a default UUID for development only. # Configure a default UUID for development only.
SYSTEM_UUID = '00000000-0000-0000-0000-000000000000' SYSTEM_UUID = '00000000-0000-0000-0000-000000000000'
INSTALL_UUID = '00000000-0000-0000-0000-000000000000'
# Store a snapshot of default settings at this point before loading any # Store a snapshot of default settings at this point before loading any
# customizable config files. # customizable config files.

View File

Binary file not shown.