minor renames in settings.py

This commit is contained in:
Jörn-Michael Miehe 2023-08-31 09:00:02 +00:00
parent 3bc453a56c
commit a8ca283467
3 changed files with 12 additions and 10 deletions

2
.vscode/launch.json vendored
View file

@ -11,7 +11,7 @@
"module": "kiwi_simple_metrics.main", "module": "kiwi_simple_metrics.main",
"env": { "env": {
"METRIC_DISK__THRESHOLD": "85", // workaround! "METRIC_DISK__THRESHOLD": "85", // workaround!
"METRIC_DISK__PARAMS": "[\"/var\", \"/\", \"/dev\"]", "METRIC_DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]",
}, },
"justMyCode": true "justMyCode": true
} }

View file

@ -17,7 +17,7 @@ def main() -> None:
# DISK metric # DISK metric
# TODO test this using timeit # TODO test this using timeit
for path in SETTINGS.disk.params: for path in SETTINGS.disk.paths:
try: try:
sv = os.statvfs(path) sv = os.statvfs(path)
percent = sv.f_bavail / sv.f_blocks * 100 percent = sv.f_bavail / sv.f_blocks * 100

View file

@ -1,8 +1,10 @@
from pydantic import BaseModel, Field import math
from pydantic import BaseModel, DirectoryPath, Field
from pydantic_settings import BaseSettings, SettingsConfigDict from pydantic_settings import BaseSettings, SettingsConfigDict
class MetricS(BaseModel): class MetricSettings(BaseModel):
# metric will be reported # metric will be reported
enabled: bool = True enabled: bool = True
@ -13,9 +15,9 @@ class MetricS(BaseModel):
inverted: bool = False inverted: bool = False
class ParamMS(MetricS): class DiskMS(MetricSettings):
# arbitrary parameters # paths to check for disk space
params: list[str] = Field(default_factory=list) paths: list[DirectoryPath] = Field(default_factory=list)
class Settings(BaseSettings): class Settings(BaseSettings):
@ -24,9 +26,9 @@ class Settings(BaseSettings):
env_nested_delimiter="__", env_nested_delimiter="__",
) )
cpu: MetricS = MetricS(threshold=100) cpu: MetricSettings = MetricSettings(threshold=math.inf)
memory: MetricS = MetricS(threshold=90) memory: MetricSettings = MetricSettings(threshold=90)
disk: ParamMS = ParamMS(threshold=85) disk: DiskMS = DiskMS(threshold=85)
SETTINGS = Settings() SETTINGS = Settings()