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

22 lines
450 B
Python
Raw Normal View History

from typing import Iterator
2023-08-31 11:17:19 +00:00
import psutil
from ..settings import SETTINGS
from ._report import Report, ReportData
def _hwdata() -> Iterator[ReportData]:
yield ReportData.from_settings(
name=SETTINGS.cpu.name,
2023-09-02 01:56:41 +00:00
value=psutil.cpu_percent(interval=SETTINGS.cpu.interval),
settings=SETTINGS.cpu,
)
2023-08-31 11:17:19 +00:00
def cpu() -> Report | None:
return Report.aggregate(
settings=SETTINGS.cpu,
get_data=_hwdata,
)