mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-23 04:21:29 +00:00
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
import strawberry
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from selfprivacy_api.models.services import ServiceStatus
|
|
from selfprivacy_api.services.prometheus import Prometheus
|
|
from selfprivacy_api.utils.monitoring import (
|
|
MonitoringQueries,
|
|
MonitoringQueryError,
|
|
MonitoringValuesResult,
|
|
MonitoringMetricsResult,
|
|
)
|
|
|
|
|
|
@strawberry.type
|
|
class Monitoring:
|
|
@strawberry.field
|
|
def cpu_usage(
|
|
self,
|
|
start: Optional[datetime] = None,
|
|
end: Optional[datetime] = None,
|
|
step: int = 60,
|
|
) -> MonitoringValuesResult:
|
|
if Prometheus().get_status() != ServiceStatus.ACTIVE:
|
|
return MonitoringQueryError(error="Prometheus is not running")
|
|
|
|
return MonitoringQueries.cpu_usage(start, end, step)
|
|
|
|
@strawberry.field
|
|
def memory_usage(
|
|
self,
|
|
start: Optional[datetime] = None,
|
|
end: Optional[datetime] = None,
|
|
step: int = 60,
|
|
) -> MonitoringValuesResult:
|
|
if Prometheus().get_status() != ServiceStatus.ACTIVE:
|
|
return MonitoringQueryError(error="Prometheus is not running")
|
|
|
|
return MonitoringQueries.memory_usage(start, end, step)
|
|
|
|
@strawberry.field
|
|
def disk_usage(
|
|
self,
|
|
start: Optional[datetime] = None,
|
|
end: Optional[datetime] = None,
|
|
step: int = 60,
|
|
) -> MonitoringMetricsResult:
|
|
if Prometheus().get_status() != ServiceStatus.ACTIVE:
|
|
return MonitoringQueryError(error="Prometheus is not running")
|
|
|
|
return MonitoringQueries.disk_usage(start, end, step)
|
|
|
|
@strawberry.field
|
|
def network_usage(
|
|
self,
|
|
start: Optional[datetime] = None,
|
|
end: Optional[datetime] = None,
|
|
step: int = 60,
|
|
) -> MonitoringMetricsResult:
|
|
if Prometheus().get_status() != ServiceStatus.ACTIVE:
|
|
return MonitoringQueryError(error="Prometheus is not running")
|
|
|
|
return MonitoringQueries.network_usage(start, end, step)
|