mirror of
https://forgejo.altau.su/lego/lego-monitoring.git
synced 2026-03-10 04:41:10 +00:00
add cpu check
This commit is contained in:
parent
8709b019ea
commit
5095057a13
12 changed files with 123 additions and 21 deletions
|
|
@ -1,2 +1,3 @@
|
|||
from .cpu import cpu_check
|
||||
from .temp import temp_check
|
||||
from .vulnix import vulnix_check
|
||||
|
|
|
|||
30
src/lego_monitoring/checks/cpu.py
Normal file
30
src/lego_monitoring/checks/cpu.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
from psutil import cpu_percent
|
||||
|
||||
from lego_monitoring.alerting import alerts
|
||||
from lego_monitoring.alerting.enum import AlertType, Severity
|
||||
from lego_monitoring.core import cvars
|
||||
|
||||
IS_TESTING = False
|
||||
|
||||
|
||||
def cpu_check() -> list[alerts.Alert]:
|
||||
percentage = cpu_percent()
|
||||
config = cvars.config.get().checks.cpu
|
||||
if config.critical_percentage and (IS_TESTING or percentage > config.critical_percentage):
|
||||
return [
|
||||
alerts.Alert(
|
||||
alert_type=AlertType.CPU,
|
||||
message=f"CPU load: {percentage:.2f}% > {config.critical_percentage:.2f}%",
|
||||
severity=Severity.CRITICAL,
|
||||
)
|
||||
]
|
||||
elif config.warning_percentage and (IS_TESTING or percentage > config.warning_percentage):
|
||||
return [
|
||||
alerts.Alert(
|
||||
alert_type=AlertType.CPU,
|
||||
message=f"CPU load: {percentage:.2f}% > {config.warning_percentage:.2f}%",
|
||||
severity=Severity.WARNING,
|
||||
)
|
||||
]
|
||||
else:
|
||||
return []
|
||||
Loading…
Add table
Add a link
Reference in a new issue