mirror of
https://github.com/yavook/kiwi-simple-metrics.git
synced 2024-11-21 23:32:59 +00:00
main blocking function: run_metrics(*_metrics)
This commit is contained in:
parent
cac6129282
commit
a6ef9c0c2b
2 changed files with 18 additions and 10 deletions
|
@ -6,14 +6,11 @@ from . import metrics
|
||||||
from .settings import SETTINGS
|
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
|
# create single report from metrics
|
||||||
report = metrics.Report.summary(
|
report = metrics.Report.summary(*reports)
|
||||||
metrics.cpu(),
|
|
||||||
metrics.memory(),
|
|
||||||
metrics.disk(),
|
|
||||||
metrics.external(),
|
|
||||||
)
|
|
||||||
|
|
||||||
# maybe print this to stdout
|
# maybe print this to stdout
|
||||||
if SETTINGS.log.enabled:
|
if SETTINGS.log.enabled:
|
||||||
|
@ -23,18 +20,24 @@ def handle_report() -> None:
|
||||||
report.push_webhook()
|
report.push_webhook()
|
||||||
|
|
||||||
|
|
||||||
async def run_metrics() -> None:
|
async def async_main() -> None:
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
asyncio.sleep(SETTINGS.interval),
|
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:
|
def main() -> None:
|
||||||
asyncio.run(run_metrics())
|
asyncio.run(async_main())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
|
from typing import Callable, TypeAlias
|
||||||
|
|
||||||
from ._report import Report
|
from ._report import Report
|
||||||
from .cpu import cpu
|
from .cpu import cpu
|
||||||
from .disk import disk
|
from .disk import disk
|
||||||
from .external import external
|
from .external import external
|
||||||
from .memory import memory
|
from .memory import memory
|
||||||
|
|
||||||
|
Metric: TypeAlias = Callable[[], Report | None]
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Report",
|
"Report",
|
||||||
|
"Metric",
|
||||||
|
|
||||||
"cpu",
|
"cpu",
|
||||||
"disk",
|
"disk",
|
||||||
|
|
Loading…
Reference in a new issue