mirror of
https://github.com/yavook/kiwi-simple-metrics.git
synced 2024-11-24 00:13:01 +00:00
29 lines
714 B
Python
29 lines
714 B
Python
import os
|
|
from typing import Iterator
|
|
|
|
from ..settings import SETTINGS
|
|
from ._report import Report, ReportData
|
|
|
|
|
|
def _hwdata() -> Iterator[ReportData]:
|
|
def get_path_statvfs(path: os.PathLike) -> dict[str, float]:
|
|
sv = os.statvfs(path)
|
|
return {
|
|
"free": sv.f_bavail,
|
|
"total": sv.f_blocks,
|
|
}
|
|
|
|
yield from sorted([
|
|
ReportData.from_free_total(
|
|
name=str(path),
|
|
**get_path_statvfs(path),
|
|
settings=SETTINGS.disk,
|
|
) for path in SETTINGS.disk.paths
|
|
], key=lambda d: d.value, reverse=True)
|
|
|
|
|
|
def disk() -> Report | None:
|
|
return Report.aggregate(
|
|
settings=SETTINGS.disk,
|
|
get_data=_hwdata,
|
|
)
|