mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 18:37:39 -02:30
add support for Accept:application/json to /api/v2/metrics
see: https://github.com/ansible/awx/issues/4144
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# All Rights Reserved.
|
||||
|
||||
from django.utils.safestring import SafeText
|
||||
from prometheus_client.parser import text_string_to_metric_families
|
||||
|
||||
# Django REST Framework
|
||||
from rest_framework import renderers
|
||||
@@ -103,3 +104,16 @@ class AnsiTextRenderer(PlainTextRenderer):
|
||||
class AnsiDownloadRenderer(PlainTextRenderer):
|
||||
|
||||
format = "ansi_download"
|
||||
|
||||
|
||||
class PrometheusJSONRenderer(renderers.JSONRenderer):
|
||||
|
||||
def render(self, data, accepted_media_type=None, renderer_context=None):
|
||||
parsed_metrics = text_string_to_metric_families(data)
|
||||
data = {}
|
||||
for family in parsed_metrics:
|
||||
for sample in family.samples:
|
||||
data[sample[0]] = {"labels": sample[1], "value": sample[2]}
|
||||
return super(PrometheusJSONRenderer, self).render(
|
||||
data, accepted_media_type, renderer_context
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user