mirror of
https://github.com/ansible/awx.git
synced 2026-05-23 16:47:45 -02:30
import awxkit
Co-authored-by: Christopher Wang <cwang@ansible.com> Co-authored-by: Jake McDermott <jmcdermott@ansible.com> Co-authored-by: Jim Ladd <jladd@redhat.com> Co-authored-by: Elijah DeLee <kdelee@redhat.com> Co-authored-by: Alan Rominger <arominge@redhat.com> Co-authored-by: Yanis Guenane <yanis@guenane.org>
This commit is contained in:
23
awxkit/awxkit/api/pages/metrics.py
Normal file
23
awxkit/awxkit/api/pages/metrics.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from prometheus_client.parser import text_string_to_metric_families
|
||||
|
||||
from awxkit.api.resources import resources
|
||||
from . import base
|
||||
from . import page
|
||||
|
||||
|
||||
class Metrics(base.Base):
|
||||
|
||||
def get(self, **query_parameters):
|
||||
request = self.connection.get(self.endpoint, query_parameters)
|
||||
self.page_identity(request, ignore_json_errors=True)
|
||||
parsed_metrics = text_string_to_metric_families(request.text)
|
||||
data = {}
|
||||
for family in parsed_metrics:
|
||||
for sample in family.samples:
|
||||
data[sample[0]] = {"labels": sample[1], "value": sample[2]}
|
||||
request.json = lambda: data
|
||||
return self.page_identity(request)
|
||||
|
||||
|
||||
page.register_page([resources.metrics,
|
||||
(resources.metrics, 'get')], Metrics)
|
||||
Reference in New Issue
Block a user