diff --git a/kiwi_simple_metrics/main.py b/kiwi_simple_metrics/main.py index 6301fea..18b2656 100644 --- a/kiwi_simple_metrics/main.py +++ b/kiwi_simple_metrics/main.py @@ -6,14 +6,11 @@ from . import metrics from .settings import SETTINGS -def handle_report() -> None: +def run_metrics(*_metrics: metrics.Metric) -> None: + reports = (metric() for metric in _metrics) + # create single report from metrics - report = metrics.Report.summary( - metrics.cpu(), - metrics.memory(), - metrics.disk(), - metrics.external(), - ) + report = metrics.Report.summary(*reports) # maybe print this to stdout if SETTINGS.log.enabled: @@ -23,18 +20,24 @@ def handle_report() -> None: report.push_webhook() -async def run_metrics() -> None: +async def async_main() -> None: loop = asyncio.get_running_loop() while True: await asyncio.gather( asyncio.sleep(SETTINGS.interval), - loop.run_in_executor(None, handle_report), + loop.run_in_executor( + None, run_metrics, + metrics.cpu, + metrics.memory, + metrics.disk, + metrics.external, + ), ) def main() -> None: - asyncio.run(run_metrics()) + asyncio.run(async_main()) if __name__ == "__main__": diff --git a/kiwi_simple_metrics/metrics/__init__.py b/kiwi_simple_metrics/metrics/__init__.py index cf1a0c0..8a2a250 100644 --- a/kiwi_simple_metrics/metrics/__init__.py +++ b/kiwi_simple_metrics/metrics/__init__.py @@ -1,11 +1,16 @@ +from typing import Callable, TypeAlias + from ._report import Report from .cpu import cpu from .disk import disk from .external import external from .memory import memory +Metric: TypeAlias = Callable[[], Report | None] + __all__ = [ "Report", + "Metric", "cpu", "disk",