diff --git a/.vscode/launch.json b/.vscode/launch.json index 4f55446..0287936 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,7 @@ "module": "kiwi_simple_metrics.main", "env": { "METRIC_DISK__THRESHOLD": "85", // workaround! - "METRIC_DISK__PARAMS": "[\"/var\", \"/\", \"/dev\"]", + "METRIC_DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]", }, "justMyCode": true } diff --git a/kiwi_simple_metrics/main.py b/kiwi_simple_metrics/main.py index 20b6edb..155cf4e 100644 --- a/kiwi_simple_metrics/main.py +++ b/kiwi_simple_metrics/main.py @@ -17,7 +17,7 @@ def main() -> None: # DISK metric # TODO test this using timeit - for path in SETTINGS.disk.params: + for path in SETTINGS.disk.paths: try: sv = os.statvfs(path) percent = sv.f_bavail / sv.f_blocks * 100 diff --git a/kiwi_simple_metrics/settings.py b/kiwi_simple_metrics/settings.py index 2ac035a..375ff75 100644 --- a/kiwi_simple_metrics/settings.py +++ b/kiwi_simple_metrics/settings.py @@ -1,8 +1,10 @@ -from pydantic import BaseModel, Field +import math + +from pydantic import BaseModel, DirectoryPath, Field from pydantic_settings import BaseSettings, SettingsConfigDict -class MetricS(BaseModel): +class MetricSettings(BaseModel): # metric will be reported enabled: bool = True @@ -13,9 +15,9 @@ class MetricS(BaseModel): inverted: bool = False -class ParamMS(MetricS): - # arbitrary parameters - params: list[str] = Field(default_factory=list) +class DiskMS(MetricSettings): + # paths to check for disk space + paths: list[DirectoryPath] = Field(default_factory=list) class Settings(BaseSettings): @@ -24,9 +26,9 @@ class Settings(BaseSettings): env_nested_delimiter="__", ) - cpu: MetricS = MetricS(threshold=100) - memory: MetricS = MetricS(threshold=90) - disk: ParamMS = ParamMS(threshold=85) + cpu: MetricSettings = MetricSettings(threshold=math.inf) + memory: MetricSettings = MetricSettings(threshold=90) + disk: DiskMS = DiskMS(threshold=85) SETTINGS = Settings()