mirror of
https://github.com/yavook/kiwi-simple-metrics.git
synced 2024-11-21 23:32:59 +00:00
concurrent metrics
This commit is contained in:
parent
e159a17f76
commit
32231f1b2d
1 changed files with 29 additions and 13 deletions
|
@ -1,12 +1,26 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import concurrent.futures
|
||||||
|
|
||||||
from . import metrics
|
from . import metrics
|
||||||
from .settings import SETTINGS
|
from .settings import SETTINGS
|
||||||
|
|
||||||
|
|
||||||
def run_metrics(*_metrics: metrics.Metric) -> None:
|
def run_metrics(
|
||||||
|
executor: concurrent.futures.Executor,
|
||||||
|
*_metrics: metrics.Metric,
|
||||||
|
) -> None:
|
||||||
|
# === conc experiment ===
|
||||||
|
|
||||||
|
futures = concurrent.futures.wait(
|
||||||
|
executor.submit(metric) for metric in _metrics
|
||||||
|
).done
|
||||||
|
|
||||||
|
print(list(future.result() for future in futures))
|
||||||
|
|
||||||
|
# === end conc ===
|
||||||
|
|
||||||
reports = (metric() for metric in _metrics)
|
reports = (metric() for metric in _metrics)
|
||||||
|
|
||||||
# create single report from metrics
|
# create single report from metrics
|
||||||
|
@ -20,14 +34,16 @@ def run_metrics(*_metrics: metrics.Metric) -> None:
|
||||||
report.push_webhook()
|
report.push_webhook()
|
||||||
|
|
||||||
|
|
||||||
async def async_main() -> None:
|
async def async_main_loop() -> None:
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
with concurrent.futures.ThreadPoolExecutor() as pool:
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
asyncio.sleep(SETTINGS.interval),
|
asyncio.sleep(SETTINGS.interval),
|
||||||
loop.run_in_executor(
|
loop.run_in_executor(
|
||||||
None, run_metrics,
|
None, run_metrics,
|
||||||
|
pool,
|
||||||
metrics.cpu,
|
metrics.cpu,
|
||||||
metrics.memory,
|
metrics.memory,
|
||||||
metrics.disk,
|
metrics.disk,
|
||||||
|
@ -37,7 +53,7 @@ async def async_main() -> None:
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
asyncio.run(async_main())
|
asyncio.run(async_main_loop())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue