SETTINGS.disk.vroot

This commit is contained in:
Jörn-Michael Miehe 2023-09-02 19:06:48 +00:00
parent b13efeca66
commit 7613fbcc46
2 changed files with 16 additions and 2 deletions

View file

@ -1,4 +1,5 @@
import os
from pathlib import PurePath
from typing import Iterator
from ..settings import SETTINGS
@ -6,16 +7,26 @@ from ._report import Report, ReportData
def _hwdata() -> Iterator[ReportData]:
def get_path_statvfs(path: os.PathLike) -> dict[str, float]:
def get_path_statvfs(path: os.PathLike) -> dict[str, int]:
sv = os.statvfs(path)
return {
"free": sv.f_bavail,
"total": sv.f_blocks,
}
def get_path_name(path: os.PathLike) -> str:
# get path and its parents
path = PurePath(path)
# if path or above is the vroot, make it a "virtual absolute" path
if SETTINGS.disk.vroot in [path, *path.parents]:
path = "/" / path.relative_to(SETTINGS.disk.vroot)
return str(path)
yield from sorted([
ReportData.from_free_total(
name=str(path),
name=get_path_name(path),
**get_path_statvfs(path),
settings=SETTINGS.disk,
) for path in SETTINGS.disk.paths

View file

@ -83,6 +83,9 @@ class DiskMS(MetricSettings):
# paths to check for disk space
paths: list[DirectoryPath] = [DirectoryPath("/")]
# path to be treated as filesystem root
vroot: DirectoryPath = DirectoryPath("/")
class ExternalMS(MetricSettings):
name: str = "External Metric"