mirror of
https://github.com/yavook/kiwi-simple-metrics.git
synced 2024-12-22 12:33:01 +00:00
minor renames in settings.py
This commit is contained in:
parent
3bc453a56c
commit
a8ca283467
3 changed files with 12 additions and 10 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue