diff --git a/selfprivacy_api/graphql/queries/monitoring.py b/selfprivacy_api/graphql/queries/monitoring.py index adf5556..1ae2498 100644 --- a/selfprivacy_api/graphql/queries/monitoring.py +++ b/selfprivacy_api/graphql/queries/monitoring.py @@ -7,18 +7,27 @@ from selfprivacy_api.utils.prometheus import PrometheusQueries, PrometheusQueryR class Monitoring: @strawberry.field def disk_usage( - start: Optional[int] = None, end: Optional[int] = None, step: int = 60 + self, + start: Optional[int] = None, + end: Optional[int] = None, + step: int = 60, ) -> PrometheusQueryResult: return PrometheusQueries.disk_usage(start, end, step) @strawberry.field def memory_usage( - start: Optional[int] = None, end: Optional[int] = None, step: int = 60 + self, + start: Optional[int] = None, + end: Optional[int] = None, + step: int = 60, ) -> PrometheusQueryResult: return PrometheusQueries.memory_usage(start, end, step) @strawberry.field def cpu_usage( - start: Optional[int] = None, end: Optional[int] = None, step: int = 60 + self, + start: Optional[int] = None, + end: Optional[int] = None, + step: int = 60, ) -> PrometheusQueryResult: return PrometheusQueries.cpu_usage(start, end, step) diff --git a/selfprivacy_api/utils/prometheus.py b/selfprivacy_api/utils/prometheus.py index a9935a2..23e7958 100644 --- a/selfprivacy_api/utils/prometheus.py +++ b/selfprivacy_api/utils/prometheus.py @@ -36,11 +36,11 @@ class PrometheusQueries: if response.status_code != 200: raise Exception("Prometheus returned unexpected HTTP status code") json = response.json() - if json['status'] != 'success': + if json["status"] != "success": raise Exception("Prometheus returned unexpected status") - result = json['data'] + result = json["data"] return PrometheusQueryResult( - result_type=result['resultType'], result=result['result'] + result_type=result["resultType"], result=result["result"] ) except Exception as error: raise Exception("Prometheus request failed! " + str(error))