mirror of
https://github.com/yavook/kiwi-simple-metrics.git
synced 2024-11-25 08:53:00 +00:00
defaults handling and metric names
This commit is contained in:
parent
953da6d511
commit
63dc67f84e
3 changed files with 22 additions and 7 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -10,8 +10,6 @@
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"module": "kiwi_simple_metrics.main",
|
"module": "kiwi_simple_metrics.main",
|
||||||
"env": {
|
"env": {
|
||||||
"METRIC_DISK__THRESHOLD": "15", // workaround!
|
|
||||||
"METRIC_DISK__INVERTED": "True", // workaround!
|
|
||||||
"METRIC_DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]",
|
"METRIC_DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]",
|
||||||
},
|
},
|
||||||
"justMyCode": true
|
"justMyCode": true
|
||||||
|
|
|
@ -37,7 +37,7 @@ def cpu_metric() -> Report | None:
|
||||||
value = psutil.cpu_percent(interval=1)
|
value = psutil.cpu_percent(interval=1)
|
||||||
return _report(
|
return _report(
|
||||||
settings=SETTINGS.cpu,
|
settings=SETTINGS.cpu,
|
||||||
name="CPU",
|
name=SETTINGS.cpu.name,
|
||||||
value=value,
|
value=value,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ def disk_metric() -> Report | None:
|
||||||
|
|
||||||
return Report(
|
return Report(
|
||||||
SETTINGS.disk.report_outer.format(
|
SETTINGS.disk.report_outer.format(
|
||||||
name="DISK FREE",
|
name=SETTINGS.disk.name,
|
||||||
inner=report_inner,
|
inner=report_inner,
|
||||||
),
|
),
|
||||||
failed=any(
|
failed=any(
|
||||||
|
|
|
@ -5,6 +5,9 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
||||||
|
|
||||||
class MetricSettings(BaseModel):
|
class MetricSettings(BaseModel):
|
||||||
|
# metric name
|
||||||
|
name: str
|
||||||
|
|
||||||
# metric will be reported
|
# metric will be reported
|
||||||
enabled: bool = True
|
enabled: bool = True
|
||||||
|
|
||||||
|
@ -18,7 +21,21 @@ class MetricSettings(BaseModel):
|
||||||
inverted: bool = False
|
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):
|
class DiskMS(MetricSettings):
|
||||||
|
name: str = "Disk Free"
|
||||||
|
threshold: float = 15
|
||||||
|
inverted: bool = True
|
||||||
|
|
||||||
# outer format string for reporting
|
# outer format string for reporting
|
||||||
report_outer: str = "{name}: [{inner}]"
|
report_outer: str = "{name}: [{inner}]"
|
||||||
|
|
||||||
|
@ -35,9 +52,9 @@ class Settings(BaseSettings):
|
||||||
env_nested_delimiter="__",
|
env_nested_delimiter="__",
|
||||||
)
|
)
|
||||||
|
|
||||||
cpu: MetricSettings = MetricSettings(threshold=math.inf)
|
cpu: CpuMS = CpuMS()
|
||||||
memory: MetricSettings = MetricSettings(threshold=90)
|
memory: MemoryMS = MemoryMS()
|
||||||
disk: DiskMS = DiskMS(threshold=15, inverted=True)
|
disk: DiskMS = DiskMS()
|
||||||
|
|
||||||
|
|
||||||
SETTINGS = Settings()
|
SETTINGS = Settings()
|
||||||
|
|
Loading…
Reference in a new issue