diff --git a/selfprivacy_api/utils/prometheus.py b/selfprivacy_api/utils/prometheus.py index c4cb0aa..786170e 100644 --- a/selfprivacy_api/utils/prometheus.py +++ b/selfprivacy_api/utils/prometheus.py @@ -33,22 +33,27 @@ class PrometheusQueries: ) @staticmethod - def cpu_usage() -> PrometheusInfo: + def cpu_usage( + start: int = int((datetime.now() - timedelta(minutes=20)).timestamp()), + end: int = int(datetime.now().timestamp()), + step: int = 60, + ) -> PrometheusInfo: """Get CPU information""" - start = int((datetime.now() - timedelta(minutes=20)).timestamp()) - end = int(datetime.now().timestamp()) + query = '100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)' - params = {"query": query, "start": start, "end": end, "step": 60} + params = {"query": query, "start": start, "end": end, "step": step} return self._send_request(params=params) @staticmethod - def disk_usage() -> PrometheusInfo: + def disk_usage( + start: int = int((datetime.now() - timedelta(minutes=20)).timestamp()), + end: int = int(datetime.now().timestamp()), + step: int = 60, + ) -> PrometheusInfo: """Get disk usage information""" - start = int((datetime.now() - timedelta(minutes=20)).timestamp()) - end = int(datetime.now().timestamp()) query = '100 - (100 * ((node_filesystem_avail_bytes{mountpoint="/",fstype!="rootfs"} ) / (node_filesystem_size_bytes{mountpoint="/",fstype!="rootfs"}) ))' - params = {"query": query, "start": start, "end": end, "step": 60} + params = {"query": query, "start": start, "end": end, "step": step} return self._send_request(params=params)