From c9424f9af8e2df0908d43d4e9b55969931e60a1f Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Wed, 24 Apr 2019 11:59:31 -0400 Subject: [PATCH] fix a few issues with license counts in /api/v2/metrics/ - switched these to gauges so people can track them over time - fixed a typo that caused `free_instances` to always be zero --- awx/main/analytics/metrics.py | 7 ++++++- awx/main/tests/functional/analytics/test_metrics.py | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/awx/main/analytics/metrics.py b/awx/main/analytics/metrics.py index 482aea829c..4219197cf4 100644 --- a/awx/main/analytics/metrics.py +++ b/awx/main/analytics/metrics.py @@ -44,6 +44,9 @@ INSTANCE_INFO = Info('awx_instance', 'Info about each node in a Tower system', [ 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',]) +LICENSE_INSTANCE_TOTAL = Gauge('awx_license_instance_total', 'Total number of managed hosts provided by your license') +LICENSE_INSTANCE_FREE = Gauge('awx_license_instance_free', 'Number of remaining managed hosts provided by your license') + def metrics(): license_info = get_license(show_key=False) @@ -54,13 +57,15 @@ def metrics(): 'tower_version': get_awx_version(), 'ansible_version': get_ansible_version(), 'license_type': license_info.get('license_type', 'UNLICENSED'), - 'free_instances': str(license_info.get('free instances', 0)), 'license_expiry': str(license_info.get('time_remaining', 0)), 'pendo_tracking': settings.PENDO_TRACKING_STATE, 'external_logger_enabled': str(settings.LOG_AGGREGATOR_ENABLED), 'external_logger_type': getattr(settings, 'LOG_AGGREGATOR_TYPE', 'None') }) + LICENSE_INSTANCE_TOTAL.set(str(license_info.get('available_instances', 0))) + LICENSE_INSTANCE_FREE.set(str(license_info.get('free_instances', 0))) + current_counts = counts(None) ORG_COUNT.set(current_counts['organization']) diff --git a/awx/main/tests/functional/analytics/test_metrics.py b/awx/main/tests/functional/analytics/test_metrics.py index 8d3bb957e7..385c299aea 100644 --- a/awx/main/tests/functional/analytics/test_metrics.py +++ b/awx/main/tests/functional/analytics/test_metrics.py @@ -28,6 +28,8 @@ EXPECTED_VALUES = { 'awx_instance_cpu':0.0, 'awx_instance_memory':0.0, 'awx_instance_info':1.0, + 'awx_license_instance_total':0, + 'awx_license_instance_free':0, }