mirror of
https://github.com/yavook/kiwi-simple-metrics.git
synced 2024-11-21 23:32:59 +00:00
better timing with concurrency
This commit is contained in:
parent
94191f3b5d
commit
f23d7f2e37
1 changed files with 26 additions and 23 deletions
|
@ -9,10 +9,7 @@ from . import metrics
|
||||||
from .settings import SETTINGS
|
from .settings import SETTINGS
|
||||||
|
|
||||||
|
|
||||||
async def run_metrics() -> None:
|
def handle_report() -> None:
|
||||||
while True:
|
|
||||||
interval = asyncio.sleep(SETTINGS.interval)
|
|
||||||
|
|
||||||
# create single report from metrics
|
# create single report from metrics
|
||||||
report = metrics.Report.summary(
|
report = metrics.Report.summary(
|
||||||
metrics.cpu(),
|
metrics.cpu(),
|
||||||
|
@ -33,13 +30,19 @@ async def run_metrics() -> None:
|
||||||
verify=not SETTINGS.webhook.insecure,
|
verify=not SETTINGS.webhook.insecure,
|
||||||
)
|
)
|
||||||
|
|
||||||
await interval
|
|
||||||
|
async def run_metrics() -> None:
|
||||||
|
loop = asyncio.get_running_loop()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
await asyncio.gather(
|
||||||
|
asyncio.sleep(SETTINGS.interval),
|
||||||
|
loop.run_in_executor(None, handle_report),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
loop = asyncio.get_event_loop()
|
asyncio.run(run_metrics())
|
||||||
loop.create_task(run_metrics())
|
|
||||||
loop.run_forever()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue