diff --git a/.vscode/launch.json b/.vscode/launch.json index f702240..3f25227 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,6 +10,7 @@ "request": "launch", "module": "kiwi_simple_metrics.main", "env": { + "METRIC__INTERVAL": "5", "METRIC__DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]", }, "justMyCode": true diff --git a/kiwi_simple_metrics/main.py b/kiwi_simple_metrics/main.py index 4891e7f..82a6bb7 100644 --- a/kiwi_simple_metrics/main.py +++ b/kiwi_simple_metrics/main.py @@ -1,14 +1,28 @@ #!/usr/bin/python3 +import asyncio + from . import metrics +from .settings import SETTINGS + + +async def run_metrics() -> None: + while True: + interval = asyncio.sleep(SETTINGS.interval) + + print(metrics.Report.concat( + metrics.cpu(), + metrics.memory(), + metrics.disk(), + )) + + await interval def main() -> None: - print(metrics.Report.concat( - metrics.cpu(), - metrics.memory(), - metrics.disk(), - )) + loop = asyncio.get_event_loop() + loop.create_task(run_metrics()) + loop.run_forever() if __name__ == "__main__": diff --git a/kiwi_simple_metrics/settings.py b/kiwi_simple_metrics/settings.py index 3d2bf11..26106c2 100644 --- a/kiwi_simple_metrics/settings.py +++ b/kiwi_simple_metrics/settings.py @@ -88,6 +88,9 @@ class Settings(BaseSettings): env_nested_delimiter="__", ) + # time between gathering reports + interval: float = 600 + # separates metrics and values in reports separator: str = ", "