selfprivacy-rest-api/selfprivacy_api/graphql/queries/monitoring.py

62 lines
1.9 KiB
Python
Raw Normal View History

2024-07-07 12:33:15 +00:00
import strawberry
from typing import Optional
from datetime import datetime
from selfprivacy_api.models.services import ServiceStatus
from selfprivacy_api.services.prometheus import Prometheus
2024-07-26 15:53:10 +00:00
from selfprivacy_api.utils.monitoring import (
MonitoringQueries,
MonitoringQueryError,
MonitoringResponse,
)
2024-06-10 01:57:41 +00:00
@strawberry.type
class Monitoring:
2024-06-10 02:27:37 +00:00
@strawberry.field
def disk_usage(
self,
start: Optional[datetime] = None,
end: Optional[datetime] = None,
step: int = 60,
2024-07-26 12:20:31 +00:00
) -> MonitoringResponse:
if Prometheus().get_status() != ServiceStatus.ACTIVE:
return MonitoringQueryError(error="Prometheus is not running")
2024-07-26 12:20:31 +00:00
return MonitoringQueries.disk_usage(start, end, step)
2024-07-08 15:18:07 +00:00
@strawberry.field
def memory_usage(
self,
start: Optional[datetime] = None,
end: Optional[datetime] = None,
step: int = 60,
2024-07-26 12:20:31 +00:00
) -> MonitoringResponse:
if Prometheus().get_status() != ServiceStatus.ACTIVE:
return MonitoringQueryError(error="Prometheus is not running")
2024-07-26 12:20:31 +00:00
return MonitoringQueries.memory_usage(start, end, step)
2024-06-10 02:27:37 +00:00
2024-06-10 01:57:41 +00:00
@strawberry.field
def cpu_usage(
self,
start: Optional[datetime] = None,
end: Optional[datetime] = None,
step: int = 60,
2024-07-26 12:20:31 +00:00
) -> MonitoringResponse:
if Prometheus().get_status() != ServiceStatus.ACTIVE:
return MonitoringQueryError(error="Prometheus is not running")
2024-07-26 12:20:31 +00:00
return MonitoringQueries.cpu_usage(start, end, step)
2024-07-26 11:50:12 +00:00
@strawberry.field
def network_usage(
self,
start: Optional[datetime] = None,
end: Optional[datetime] = None,
step: int = 60,
2024-07-26 12:20:31 +00:00
) -> MonitoringResponse:
if Prometheus().get_status() != ServiceStatus.ACTIVE:
return MonitoringQueryError(error="Prometheus is not running")
2024-07-26 12:20:31 +00:00
return MonitoringQueries.cpu_usage(start, end, step)