kiwi-simple-metrics/kiwi_simple_metrics/metrics/cpu.py

21 lines
368 B
Python
Raw Normal View History

2023-08-31 11:17:19 +00:00
import psutil
from ..settings import SETTINGS
from ._report import Report, ReportData
def _hwdata() -> ReportData:
return ReportData(
name=SETTINGS.cpu.name,
value=psutil.cpu_percent(interval=1),
)
2023-08-31 11:17:19 +00:00
def cpu() -> Report | None:
if not SETTINGS.cpu.enabled:
return None
data = _hwdata()
return data.report(SETTINGS.cpu)