kiwi-simple-metrics/kiwi_simple_metrics/settings.py

35 lines
868 B
Python
Raw Normal View History

2023-08-31 09:00:02 +00:00
import math
from pydantic import BaseModel, DirectoryPath, Field
2023-08-30 22:01:31 +00:00
from pydantic_settings import BaseSettings, SettingsConfigDict
2023-08-31 09:00:02 +00:00
class MetricSettings(BaseModel):
2023-08-30 22:01:31 +00:00
# metric will be reported
enabled: bool = True
# if the metric value exceeds this percentage, the report fails
threshold: float
# if True, this metric fails when the value falls below the `threshold`
inverted: bool = False
2023-08-31 09:00:02 +00:00
class DiskMS(MetricSettings):
# paths to check for disk space
paths: list[DirectoryPath] = Field(default_factory=list)
2023-08-30 22:01:31 +00:00
class Settings(BaseSettings):
model_config = SettingsConfigDict(
env_prefix="METRIC_",
env_nested_delimiter="__",
)
2023-08-31 09:00:02 +00:00
cpu: MetricSettings = MetricSettings(threshold=math.inf)
memory: MetricSettings = MetricSettings(threshold=90)
disk: DiskMS = DiskMS(threshold=85)
2023-08-30 22:01:31 +00:00
SETTINGS = Settings()