disk report "used" instead of "free"

This commit is contained in:
Jörn-Michael Miehe 2023-08-31 11:44:41 +00:00
parent 06f8ba1316
commit a9cf044fe1
2 changed files with 14 additions and 12 deletions

View file

@ -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,

View file

@ -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)