From a9cf044fe1b8ea5495a8704045bba49941726e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 31 Aug 2023 11:44:41 +0000 Subject: [PATCH] disk report "used" instead of "free" --- kiwi_simple_metrics/metrics/disk.py | 8 ++++---- kiwi_simple_metrics/settings.py | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) 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)