mirror of
https://forgejo.altau.su/lego/lego-monitoring.git
synced 2026-03-12 05:35:19 +00:00
add slugs to checks, enabling sending them to healthchecks
This commit is contained in:
parent
be7b3dbeed
commit
5c57e1765e
8 changed files with 87 additions and 7 deletions
|
|
@ -1,21 +1,27 @@
|
|||
from socket import gethostname
|
||||
|
||||
from psutil import cpu_percent
|
||||
|
||||
from lego_monitoring.alerting.alert import Alert
|
||||
from lego_monitoring.alerting.enum import AlertType, Severity
|
||||
from lego_monitoring.core import cvars
|
||||
|
||||
from .utils import format_for_healthchecks_slug
|
||||
|
||||
IS_TESTING = False
|
||||
|
||||
|
||||
def cpu_check() -> list[Alert]:
|
||||
percentage = cpu_percent()
|
||||
config = cvars.config.get().checks.cpu
|
||||
slug = f"{format_for_healthchecks_slug(gethostname())}-cpu"
|
||||
if config.critical_percentage and (IS_TESTING or percentage >= config.critical_percentage):
|
||||
return [
|
||||
Alert(
|
||||
alert_type=AlertType.CPU,
|
||||
message=f"CPU load: {percentage:.2f}% >= {config.critical_percentage:.2f}%",
|
||||
severity=Severity.CRITICAL,
|
||||
healthchecks_slug=slug,
|
||||
)
|
||||
]
|
||||
elif config.warning_percentage and (IS_TESTING or percentage >= config.warning_percentage):
|
||||
|
|
@ -24,7 +30,15 @@ def cpu_check() -> list[Alert]:
|
|||
alert_type=AlertType.CPU,
|
||||
message=f"CPU load: {percentage:.2f}% >= {config.warning_percentage:.2f}%",
|
||||
severity=Severity.WARNING,
|
||||
healthchecks_slug=slug,
|
||||
)
|
||||
]
|
||||
else:
|
||||
return [Alert(alert_type=AlertType.CPU, message=f"CPU load: {percentage:.2f}% (nominal)", severity=Severity.OK)]
|
||||
return [
|
||||
Alert(
|
||||
alert_type=AlertType.CPU,
|
||||
message=f"CPU load: {percentage:.2f}% (nominal)",
|
||||
severity=Severity.OK,
|
||||
healthchecks_slug=slug,
|
||||
)
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue