mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 04:01:27 +00:00
fix: Do not try to fetch stats if prometheus is not active
This commit is contained in:
parent
8bd1a9354f
commit
dc64ce1cfa
|
@ -1,7 +1,9 @@
|
||||||
import strawberry
|
import strawberry
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from selfprivacy_api.utils.monitoring import MonitoringQueries, MonitoringResponse
|
from selfprivacy_api.models.services import ServiceStatus
|
||||||
|
from selfprivacy_api.services.prometheus import Prometheus
|
||||||
|
from selfprivacy_api.utils.monitoring import MonitoringQueries, MonitoringQueryError, MonitoringResponse
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
|
@ -13,6 +15,9 @@ class Monitoring:
|
||||||
end: Optional[datetime] = None,
|
end: Optional[datetime] = None,
|
||||||
step: int = 60,
|
step: int = 60,
|
||||||
) -> MonitoringResponse:
|
) -> MonitoringResponse:
|
||||||
|
if Prometheus().get_status() != ServiceStatus.ACTIVE:
|
||||||
|
return MonitoringQueryError(error="Prometheus is not running")
|
||||||
|
|
||||||
return MonitoringQueries.disk_usage(start, end, step)
|
return MonitoringQueries.disk_usage(start, end, step)
|
||||||
|
|
||||||
@strawberry.field
|
@strawberry.field
|
||||||
|
@ -22,6 +27,9 @@ class Monitoring:
|
||||||
end: Optional[datetime] = None,
|
end: Optional[datetime] = None,
|
||||||
step: int = 60,
|
step: int = 60,
|
||||||
) -> MonitoringResponse:
|
) -> MonitoringResponse:
|
||||||
|
if Prometheus().get_status() != ServiceStatus.ACTIVE:
|
||||||
|
return MonitoringQueryError(error="Prometheus is not running")
|
||||||
|
|
||||||
return MonitoringQueries.memory_usage(start, end, step)
|
return MonitoringQueries.memory_usage(start, end, step)
|
||||||
|
|
||||||
@strawberry.field
|
@strawberry.field
|
||||||
|
@ -31,6 +39,9 @@ class Monitoring:
|
||||||
end: Optional[datetime] = None,
|
end: Optional[datetime] = None,
|
||||||
step: int = 60,
|
step: int = 60,
|
||||||
) -> MonitoringResponse:
|
) -> MonitoringResponse:
|
||||||
|
if Prometheus().get_status() != ServiceStatus.ACTIVE:
|
||||||
|
return MonitoringQueryError(error="Prometheus is not running")
|
||||||
|
|
||||||
return MonitoringQueries.cpu_usage(start, end, step)
|
return MonitoringQueries.cpu_usage(start, end, step)
|
||||||
|
|
||||||
@strawberry.field
|
@strawberry.field
|
||||||
|
@ -40,4 +51,7 @@ class Monitoring:
|
||||||
end: Optional[datetime] = None,
|
end: Optional[datetime] = None,
|
||||||
step: int = 60,
|
step: int = 60,
|
||||||
) -> MonitoringResponse:
|
) -> MonitoringResponse:
|
||||||
|
if Prometheus().get_status() != ServiceStatus.ACTIVE:
|
||||||
|
return MonitoringQueryError(error="Prometheus is not running")
|
||||||
|
|
||||||
return MonitoringQueries.cpu_usage(start, end, step)
|
return MonitoringQueries.cpu_usage(start, end, step)
|
||||||
|
|
Loading…
Reference in a new issue