mirror of
https://forgejo.altau.su/lego/lego-monitoring.git
synced 2026-03-10 12:45:19 +00:00
30 lines
1,018 B
Python
30 lines
1,018 B
Python
from psutil import virtual_memory
|
|
|
|
from lego_monitoring.alerting.alert import Alert
|
|
from lego_monitoring.alerting.enum import AlertType, Severity
|
|
from lego_monitoring.core import cvars
|
|
|
|
IS_TESTING = False
|
|
|
|
|
|
def ram_check() -> list[Alert]:
|
|
percentage = virtual_memory().percent
|
|
config = cvars.config.get().checks.ram
|
|
if config.critical_percentage and (IS_TESTING or percentage > config.critical_percentage):
|
|
return [
|
|
Alert(
|
|
alert_type=AlertType.RAM,
|
|
message=f"RAM usage: {percentage:.2f}% > {config.critical_percentage:.2f}%",
|
|
severity=Severity.CRITICAL,
|
|
)
|
|
]
|
|
elif config.warning_percentage and (IS_TESTING or percentage > config.warning_percentage):
|
|
return [
|
|
Alert(
|
|
alert_type=AlertType.RAM,
|
|
message=f"RAM usage: {percentage:.2f}% > {config.warning_percentage:.2f}%",
|
|
severity=Severity.WARNING,
|
|
)
|
|
]
|
|
else:
|
|
return []
|