diff --git a/.vscode/launch.json b/.vscode/launch.json index 3f25227..cd3eae0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,7 @@ "module": "kiwi_simple_metrics.main", "env": { "METRIC__INTERVAL": "5", + "METRIC__QUIET": "False", "METRIC__DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]", }, "justMyCode": true diff --git a/kiwi_simple_metrics/main.py b/kiwi_simple_metrics/main.py index 82a6bb7..a0fe787 100644 --- a/kiwi_simple_metrics/main.py +++ b/kiwi_simple_metrics/main.py @@ -10,11 +10,14 @@ async def run_metrics() -> None: while True: interval = asyncio.sleep(SETTINGS.interval) - print(metrics.Report.concat( + report = metrics.Report.concat( metrics.cpu(), metrics.memory(), metrics.disk(), - )) + ) + + if not SETTINGS.quiet: + print(report) await interval diff --git a/kiwi_simple_metrics/metrics/_report.py b/kiwi_simple_metrics/metrics/_report.py index c609f1b..c3067cc 100644 --- a/kiwi_simple_metrics/metrics/_report.py +++ b/kiwi_simple_metrics/metrics/_report.py @@ -34,6 +34,14 @@ class Report: result: str failed: bool = False + def __str__(self) -> str: + state = "OK" if not self.failed else "FAIL" + + return SETTINGS.report_stdout.format( + state=state, + result=self.result, + ) + @classmethod def concat(cls, *_reports: Any) -> Self: reports = [ diff --git a/kiwi_simple_metrics/settings.py b/kiwi_simple_metrics/settings.py index 26106c2..765cd06 100644 --- a/kiwi_simple_metrics/settings.py +++ b/kiwi_simple_metrics/settings.py @@ -91,6 +91,12 @@ class Settings(BaseSettings): # time between gathering reports interval: float = 600 + # if False, prints reports to stdout + quiet: bool = True + + # how to format reports to stdout + report_stdout: str = "[{state}] {result}" + # separates metrics and values in reports separator: str = ", "