mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 04:01:27 +00:00
chore: Review fixes
This commit is contained in:
parent
6f18eefc25
commit
e0380d149b
|
@ -33,5 +33,5 @@ class AddMonitoring(Migration):
|
|||
if "monitoring" not in data["modules"]:
|
||||
data["modules"]["monitoring"] = {
|
||||
"enable": True,
|
||||
"location": BlockDevices().get_root_block_device().name
|
||||
"location": BlockDevices().get_root_block_device().name,
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ from selfprivacy_api.services.prometheus.icon import PROMETHEUS_ICON
|
|||
|
||||
|
||||
class Prometheus(Service):
|
||||
"""Class representing Pleroma service."""
|
||||
"""Class representing Prometheus service."""
|
||||
|
||||
@staticmethod
|
||||
def get_id() -> str:
|
||||
|
@ -24,7 +24,7 @@ class Prometheus(Service):
|
|||
|
||||
@staticmethod
|
||||
def get_description() -> str:
|
||||
return "Prometheus is a free software application used for event monitoring and alerting."
|
||||
return "Prometheus is used for resource monitoring and alerts."
|
||||
|
||||
@staticmethod
|
||||
def get_svg_icon() -> str:
|
||||
|
@ -49,7 +49,7 @@ class Prometheus(Service):
|
|||
|
||||
@staticmethod
|
||||
def get_backup_description() -> str:
|
||||
return "For Prometheus backups are not available."
|
||||
return "Backups are not available for Prometheus."
|
||||
|
||||
@staticmethod
|
||||
def get_status() -> ServiceStatus:
|
||||
|
|
|
@ -44,81 +44,105 @@ class PrometheusQueries:
|
|||
|
||||
@staticmethod
|
||||
def cpu_usage(
|
||||
start: Optional[int] = None,
|
||||
end: Optional[int] = None,
|
||||
start: Optional[datetime] = None,
|
||||
end: Optional[datetime] = None,
|
||||
step: int = 60, # seconds
|
||||
) -> PrometheusQueryResult:
|
||||
"""
|
||||
Get CPU information.
|
||||
|
||||
Args:
|
||||
start (int, optional): Unix timestamp indicating the start time.
|
||||
start (datetime, optional): The start time.
|
||||
Defaults to 20 minutes ago if not provided.
|
||||
end (int, optional): Unix timestamp indicating the end time.
|
||||
end (datetime, optional): The end time.
|
||||
Defaults to current time if not provided.
|
||||
step (int): Interval in seconds for querying disk usage data.
|
||||
"""
|
||||
|
||||
if not start:
|
||||
start = int((datetime.now() - timedelta(minutes=20)).timestamp())
|
||||
if start is None:
|
||||
start = datetime.now() - timedelta(minutes=20)
|
||||
|
||||
if not end:
|
||||
end = int(datetime.now().timestamp())
|
||||
if end is None:
|
||||
end = datetime.now()
|
||||
|
||||
start_timestamp = int(start.timestamp())
|
||||
end_timestamp = int(end.timestamp())
|
||||
|
||||
query = '100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)'
|
||||
|
||||
return PrometheusQueries._send_query(query, start, end, step)
|
||||
return PrometheusQueries._send_query(
|
||||
query,
|
||||
start_timestamp,
|
||||
end_timestamp,
|
||||
step,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def memory_usage(
|
||||
start: Optional[int] = None,
|
||||
end: Optional[int] = None,
|
||||
start: Optional[datetime] = None,
|
||||
end: Optional[datetime] = None,
|
||||
step: int = 60, # seconds
|
||||
) -> PrometheusQueryResult:
|
||||
"""
|
||||
Get memory usage.
|
||||
|
||||
Args:
|
||||
start (int, optional): Unix timestamp indicating the start time.
|
||||
start (datetime, optional): The start time.
|
||||
Defaults to 20 minutes ago if not provided.
|
||||
end (int, optional): Unix timestamp indicating the end time.
|
||||
end (datetime, optional): The end time.
|
||||
Defaults to current time if not provided.
|
||||
step (int): Interval in seconds for querying memory usage data.
|
||||
"""
|
||||
|
||||
if not start:
|
||||
start = int((datetime.now() - timedelta(minutes=20)).timestamp())
|
||||
if start is None:
|
||||
start = datetime.now() - timedelta(minutes=20)
|
||||
|
||||
if not end:
|
||||
end = int(datetime.now().timestamp())
|
||||
if end is None:
|
||||
end = datetime.now()
|
||||
|
||||
start_timestamp = int(start.timestamp())
|
||||
end_timestamp = int(end.timestamp())
|
||||
|
||||
query = "100 - (100 * (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes))"
|
||||
|
||||
return PrometheusQueries._send_query(query, start, end, step)
|
||||
return PrometheusQueries._send_query(
|
||||
query,
|
||||
start_timestamp,
|
||||
end_timestamp,
|
||||
step,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def disk_usage(
|
||||
start: Optional[int] = None,
|
||||
end: Optional[int] = None,
|
||||
start: Optional[datetime] = None,
|
||||
end: Optional[datetime] = None,
|
||||
step: int = 60, # seconds
|
||||
) -> PrometheusQueryResult:
|
||||
"""
|
||||
Get disk usage information.
|
||||
|
||||
Args:
|
||||
start (int, optional): Unix timestamp indicating the start time.
|
||||
start (datetime, optional): The start time.
|
||||
Defaults to 20 minutes ago if not provided.
|
||||
end (int, optional): Unix timestamp indicating the end time.
|
||||
end (datetime, optional): The end time.
|
||||
Defaults to current time if not provided.
|
||||
step (int): Interval in seconds for querying disk usage data.
|
||||
"""
|
||||
|
||||
if not start:
|
||||
start = int((datetime.now() - timedelta(minutes=20)).timestamp())
|
||||
if start is None:
|
||||
start = datetime.now() - timedelta(minutes=20)
|
||||
|
||||
if not end:
|
||||
end = int(datetime.now().timestamp())
|
||||
if end is None:
|
||||
end = datetime.now()
|
||||
|
||||
start_timestamp = int(start.timestamp())
|
||||
end_timestamp = int(end.timestamp())
|
||||
|
||||
query = """100 - (100 * sum by (device) (node_filesystem_avail_bytes{fstype!="rootfs"}) / sum by (device) (node_filesystem_size_bytes{fstype!="rootfs"}))"""
|
||||
|
||||
return PrometheusQueries._send_query(query, start, end, step)
|
||||
return PrometheusQueries._send_query(
|
||||
query,
|
||||
start_timestamp,
|
||||
end_timestamp,
|
||||
step,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue