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-31 11:09:19 +00:00
|
|
|
# metric name
|
|
|
|
name: str
|
|
|
|
|
2023-08-30 22:01:31 +00:00
|
|
|
# metric will be reported
|
|
|
|
enabled: bool = True
|
|
|
|
|
2023-08-31 09:00:22 +00:00
|
|
|
# format string to report the metric
|
|
|
|
report: str = "{name}: {value:.2f}%"
|
|
|
|
|
2023-08-30 22:01:31 +00:00
|
|
|
# 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 11:09:19 +00:00
|
|
|
class CpuMS(MetricSettings):
|
|
|
|
name: str = "CPU"
|
|
|
|
threshold: float = math.inf
|
|
|
|
|
|
|
|
|
|
|
|
class MemoryMS(MetricSettings):
|
|
|
|
name: str = "Memory"
|
|
|
|
threshold: float = 90
|
|
|
|
|
|
|
|
|
2023-08-31 09:00:02 +00:00
|
|
|
class DiskMS(MetricSettings):
|
2023-08-31 11:09:19 +00:00
|
|
|
name: str = "Disk Free"
|
|
|
|
threshold: float = 15
|
|
|
|
inverted: bool = True
|
|
|
|
|
2023-08-31 11:02:54 +00:00
|
|
|
# outer format string for reporting
|
|
|
|
report_outer: str = "{name}: [{inner}]"
|
|
|
|
|
2023-08-31 09:00:02 +00:00
|
|
|
# paths to check for disk space
|
|
|
|
paths: list[DirectoryPath] = Field(default_factory=list)
|
2023-08-30 22:01:31 +00:00
|
|
|
|
2023-08-31 11:02:54 +00:00
|
|
|
# include only `count` many of the paths with the least free space
|
|
|
|
count: int = 1
|
|
|
|
|
2023-08-30 22:01:31 +00:00
|
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
|
|
model_config = SettingsConfigDict(
|
|
|
|
env_prefix="METRIC_",
|
|
|
|
env_nested_delimiter="__",
|
|
|
|
)
|
|
|
|
|
2023-08-31 11:09:19 +00:00
|
|
|
cpu: CpuMS = CpuMS()
|
|
|
|
memory: MemoryMS = MemoryMS()
|
|
|
|
disk: DiskMS = DiskMS()
|
2023-08-30 22:01:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
SETTINGS = Settings()
|