defaults handling and metric names

This commit is contained in:
Jörn-Michael Miehe 2023-08-31 11:09:19 +00:00
parent 953da6d511
commit 63dc67f84e
3 changed files with 22 additions and 7 deletions

2
.vscode/launch.json vendored
View file

@ -10,8 +10,6 @@
"request": "launch",
"module": "kiwi_simple_metrics.main",
"env": {
"METRIC_DISK__THRESHOLD": "15", // workaround!
"METRIC_DISK__INVERTED": "True", // workaround!
"METRIC_DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]",
},
"justMyCode": true

View file

@ -37,7 +37,7 @@ def cpu_metric() -> Report | None:
value = psutil.cpu_percent(interval=1)
return _report(
settings=SETTINGS.cpu,
name="CPU",
name=SETTINGS.cpu.name,
value=value,
)
@ -71,7 +71,7 @@ def disk_metric() -> Report | None:
return Report(
SETTINGS.disk.report_outer.format(
name="DISK FREE",
name=SETTINGS.disk.name,
inner=report_inner,
),
failed=any(

View file

@ -5,6 +5,9 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
class MetricSettings(BaseModel):
# metric name
name: str
# metric will be reported
enabled: bool = True
@ -18,7 +21,21 @@ class MetricSettings(BaseModel):
inverted: bool = False
class CpuMS(MetricSettings):
name: str = "CPU"
threshold: float = math.inf
class MemoryMS(MetricSettings):
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}]"
@ -35,9 +52,9 @@ class Settings(BaseSettings):
env_nested_delimiter="__",
)
cpu: MetricSettings = MetricSettings(threshold=math.inf)
memory: MetricSettings = MetricSettings(threshold=90)
disk: DiskMS = DiskMS(threshold=15, inverted=True)
cpu: CpuMS = CpuMS()
memory: MemoryMS = MemoryMS()
disk: DiskMS = DiskMS()
SETTINGS = Settings()