Add subsystem metrics

- Adds a Metrics() class that can track data such as number of
events the callback receiver inserted into database
- Exposes this metric data at the api/v2/metrics/ endpoint.
This data is prometheus-friendly
- Metric data is stored in memory, then periodically saved to Redis.
- Metric data is periodically broadcast to other nodes in the cluster,
so that each node has a copy of the most recent metric data collected.
This commit is contained in:
Seth Foster
2021-03-23 16:05:10 -04:00
parent f8a698d127
commit 0c569c67fd
12 changed files with 410 additions and 20 deletions

View File

@@ -14,6 +14,7 @@ from rest_framework.exceptions import PermissionDenied
# AWX
# from awx.main.analytics import collectors
import awx.main.analytics.subsystem_metrics as s_metrics
from awx.main.analytics.metrics import metrics
from awx.api import renderers
@@ -33,5 +34,10 @@ class MetricsView(APIView):
def get(self, request):
''' Show Metrics Details '''
if request.user.is_superuser or request.user.is_system_auditor:
return Response(metrics().decode('UTF-8'))
metrics_to_show = ''
if not request.query_params.get('subsystemonly', "0") == "1":
metrics_to_show += metrics().decode('UTF-8')
if not request.query_params.get('dbonly', "0") == "1":
metrics_to_show += s_metrics.metrics(request)
return Response(metrics_to_show)
raise PermissionDenied()