diff --git a/kiwi_simple_metrics/metrics/disk.py b/kiwi_simple_metrics/metrics/disk.py index cdc46b8..c30ee0c 100644 --- a/kiwi_simple_metrics/metrics/disk.py +++ b/kiwi_simple_metrics/metrics/disk.py @@ -8,17 +8,17 @@ def disk() -> Report | None: if not SETTINGS.disk.enabled: return None - def path_to_free_percent(path: os.PathLike) -> float: + def path_to_used_percent(path: os.PathLike) -> float: try: sv = os.statvfs(path) - return sv.f_bavail / sv.f_blocks * 100 + return (1 - sv.f_bavail / sv.f_blocks) * 100 except ZeroDivisionError: return 0 data = sorted([ - (str(path), path_to_free_percent(path)) + (str(path), path_to_used_percent(path)) for path in SETTINGS.disk.paths - ], key=lambda d: d[1]) + ], key=lambda d: d[1], reverse=True) reports = [Report.new( settings=SETTINGS.disk, diff --git a/kiwi_simple_metrics/settings.py b/kiwi_simple_metrics/settings.py index 8011ee0..e534b97 100644 --- a/kiwi_simple_metrics/settings.py +++ b/kiwi_simple_metrics/settings.py @@ -1,4 +1,5 @@ import math +from typing import Literal from pydantic import BaseModel, DirectoryPath, Field from pydantic_settings import BaseSettings, SettingsConfigDict @@ -26,18 +27,19 @@ class CpuMS(MetricSettings): threshold: float = math.inf -class MemoryMS(MetricSettings): +class MultiMS(MetricSettings): + # outer format string for reporting + report_outer: str = "{name}: [{inner}]" + + +class MemoryMS(MultiMS): name: str = "Memory" threshold: float = 90 -class DiskMS(MetricSettings): - name: str = "Disk Free" - threshold: float = 15 - inverted: bool = True - - # outer format string for reporting - report_outer: str = "{name}: [{inner}]" +class DiskMS(MultiMS): + name: str = "Disk Used" + threshold: float = 85 # paths to check for disk space paths: list[DirectoryPath] = Field(default_factory=list)