From 7613fbcc4608e1cb09fd8c997d28989366a44666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Sat, 2 Sep 2023 19:06:48 +0000 Subject: [PATCH 1/2] SETTINGS.disk.vroot --- kiwi_simple_metrics/metrics/disk.py | 15 +++++++++++++-- kiwi_simple_metrics/settings/metric.py | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/kiwi_simple_metrics/metrics/disk.py b/kiwi_simple_metrics/metrics/disk.py index cc78884..ff072ed 100644 --- a/kiwi_simple_metrics/metrics/disk.py +++ b/kiwi_simple_metrics/metrics/disk.py @@ -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 diff --git a/kiwi_simple_metrics/settings/metric.py b/kiwi_simple_metrics/settings/metric.py index f785510..485eb07 100644 --- a/kiwi_simple_metrics/settings/metric.py +++ b/kiwi_simple_metrics/settings/metric.py @@ -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" From e18b756c2b9ef682206e2b514a1c6b13fc594f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Sat, 2 Sep 2023 19:07:31 +0000 Subject: [PATCH 2/2] version bump --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5e5ff75..57de706 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ license = "MIT" name = "kiwi-simple-metrics" packages = [{include = "kiwi_simple_metrics"}] readme = "README.md" -version = "0.1.0" +version = "0.1.2" [tool.poetry.dependencies] psutil = "^5.9.5"