mirror of
https://github.com/yavook/kiwi-simple-metrics.git
synced 2024-11-22 07:33:00 +00:00
Merge branch 'release/0.1.2'
This commit is contained in:
commit
0c946292a1
3 changed files with 17 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
from pathlib import PurePath
|
||||||
from typing import Iterator
|
from typing import Iterator
|
||||||
|
|
||||||
from ..settings import SETTINGS
|
from ..settings import SETTINGS
|
||||||
|
@ -6,16 +7,26 @@ from ._report import Report, ReportData
|
||||||
|
|
||||||
|
|
||||||
def _hwdata() -> Iterator[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)
|
sv = os.statvfs(path)
|
||||||
return {
|
return {
|
||||||
"free": sv.f_bavail,
|
"free": sv.f_bavail,
|
||||||
"total": sv.f_blocks,
|
"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([
|
yield from sorted([
|
||||||
ReportData.from_free_total(
|
ReportData.from_free_total(
|
||||||
name=str(path),
|
name=get_path_name(path),
|
||||||
**get_path_statvfs(path),
|
**get_path_statvfs(path),
|
||||||
settings=SETTINGS.disk,
|
settings=SETTINGS.disk,
|
||||||
) for path in SETTINGS.disk.paths
|
) for path in SETTINGS.disk.paths
|
||||||
|
|
|
@ -83,6 +83,9 @@ class DiskMS(MetricSettings):
|
||||||
# paths to check for disk space
|
# paths to check for disk space
|
||||||
paths: list[DirectoryPath] = [DirectoryPath("/")]
|
paths: list[DirectoryPath] = [DirectoryPath("/")]
|
||||||
|
|
||||||
|
# path to be treated as filesystem root
|
||||||
|
vroot: DirectoryPath = DirectoryPath("/")
|
||||||
|
|
||||||
|
|
||||||
class ExternalMS(MetricSettings):
|
class ExternalMS(MetricSettings):
|
||||||
name: str = "External Metric"
|
name: str = "External Metric"
|
||||||
|
|
|
@ -5,7 +5,7 @@ license = "MIT"
|
||||||
name = "kiwi-simple-metrics"
|
name = "kiwi-simple-metrics"
|
||||||
packages = [{include = "kiwi_simple_metrics"}]
|
packages = [{include = "kiwi_simple_metrics"}]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
version = "0.1.0"
|
version = "0.1.2"
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
psutil = "^5.9.5"
|
psutil = "^5.9.5"
|
||||||
|
|
Loading…
Reference in a new issue