2024-07-07 12:33:15 +00:00
|
|
|
import strawberry
|
2024-07-10 09:43:00 +00:00
|
|
|
from typing import Optional
|
2024-07-15 14:16:24 +00:00
|
|
|
from datetime import datetime
|
2024-07-26 15:50:00 +00:00
|
|
|
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,
|
2024-07-27 12:37:38 +00:00
|
|
|
MonitoringValuesResult,
|
|
|
|
MonitoringMetricsResult,
|
2024-07-26 15:53:10 +00:00
|
|
|
)
|
2024-06-10 01:57:41 +00:00
|
|
|
|
|
|
|
|
2024-07-29 12:53:41 +00:00
|
|
|
@strawberry.type
|
|
|
|
class CpuMonitoring:
|
|
|
|
start: Optional[datetime]
|
|
|
|
end: Optional[datetime]
|
|
|
|
step: int
|
|
|
|
|
|
|
|
@strawberry.field
|
|
|
|
def overall_usage(self) -> MonitoringValuesResult:
|
|
|
|
if Prometheus().get_status() != ServiceStatus.ACTIVE:
|
|
|
|
return MonitoringQueryError(error="Prometheus is not running")
|
|
|
|
|
|
|
|
return MonitoringQueries.cpu_usage(self.start, self.end, self.step)
|
|
|
|
|
|
|
|
|
|
|
|
@strawberry.type
|
|
|
|
class MemoryMonitoring:
|
|
|
|
start: Optional[datetime]
|
|
|
|
end: Optional[datetime]
|
|
|
|
step: int
|
|
|
|
|
|
|
|
@strawberry.field
|
|
|
|
def overall_usage(self) -> MonitoringValuesResult:
|
|
|
|
if Prometheus().get_status() != ServiceStatus.ACTIVE:
|
|
|
|
return MonitoringQueryError(error="Prometheus is not running")
|
|
|
|
|
|
|
|
return MonitoringQueries.memory_usage(self.start, self.end, self.step)
|
|
|
|
|
|
|
|
|
|
|
|
@strawberry.type
|
|
|
|
class DiskMonitoring:
|
|
|
|
start: Optional[datetime]
|
|
|
|
end: Optional[datetime]
|
|
|
|
step: int
|
|
|
|
|
|
|
|
@strawberry.field
|
|
|
|
def overall_usage(self) -> MonitoringMetricsResult:
|
|
|
|
if Prometheus().get_status() != ServiceStatus.ACTIVE:
|
|
|
|
return MonitoringQueryError(error="Prometheus is not running")
|
|
|
|
|
|
|
|
return MonitoringQueries.disk_usage(self.start, self.end, self.step)
|
|
|
|
|
|
|
|
|
|
|
|
@strawberry.type
|
|
|
|
class NetworkMonitoring:
|
|
|
|
start: Optional[datetime]
|
|
|
|
end: Optional[datetime]
|
|
|
|
step: int
|
|
|
|
|
|
|
|
@strawberry.field
|
|
|
|
def overall_usage(self) -> MonitoringMetricsResult:
|
|
|
|
if Prometheus().get_status() != ServiceStatus.ACTIVE:
|
|
|
|
return MonitoringQueryError(error="Prometheus is not running")
|
|
|
|
|
|
|
|
return MonitoringQueries.network_usage(self.start, self.end, self.step)
|
|
|
|
|
|
|
|
|
2024-06-10 01:57:41 +00:00
|
|
|
@strawberry.type
|
|
|
|
class Monitoring:
|
2024-06-10 02:27:37 +00:00
|
|
|
@strawberry.field
|
2024-07-27 12:37:38 +00:00
|
|
|
def cpu_usage(
|
2024-07-15 14:00:36 +00:00
|
|
|
self,
|
2024-07-15 14:16:24 +00:00
|
|
|
start: Optional[datetime] = None,
|
|
|
|
end: Optional[datetime] = None,
|
2024-07-15 14:00:36 +00:00
|
|
|
step: int = 60,
|
2024-07-29 12:53:41 +00:00
|
|
|
) -> CpuMonitoring:
|
|
|
|
return CpuMonitoring(start=start, end=end, step=step)
|
2024-07-08 15:18:07 +00:00
|
|
|
|
|
|
|
@strawberry.field
|
2024-07-10 12:53:56 +00:00
|
|
|
def memory_usage(
|
2024-07-15 14:00:36 +00:00
|
|
|
self,
|
2024-07-15 14:16:24 +00:00
|
|
|
start: Optional[datetime] = None,
|
|
|
|
end: Optional[datetime] = None,
|
2024-07-15 14:00:36 +00:00
|
|
|
step: int = 60,
|
2024-07-29 12:53:41 +00:00
|
|
|
) -> MemoryMonitoring:
|
|
|
|
return MemoryMonitoring(start=start, end=end, step=step)
|
2024-06-10 02:27:37 +00:00
|
|
|
|
2024-06-10 01:57:41 +00:00
|
|
|
@strawberry.field
|
2024-07-27 12:37:38 +00:00
|
|
|
def disk_usage(
|
2024-07-15 14:00:36 +00:00
|
|
|
self,
|
2024-07-15 14:16:24 +00:00
|
|
|
start: Optional[datetime] = None,
|
|
|
|
end: Optional[datetime] = None,
|
2024-07-15 14:00:36 +00:00
|
|
|
step: int = 60,
|
2024-07-29 12:53:41 +00:00
|
|
|
) -> DiskMonitoring:
|
|
|
|
return DiskMonitoring(start=start, end=end, step=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-29 12:53:41 +00:00
|
|
|
) -> NetworkMonitoring:
|
|
|
|
return NetworkMonitoring(start=start, end=end, step=step)
|