diff --git a/exporter.py b/exporter.py index 03fc141..899c626 100644 --- a/exporter.py +++ b/exporter.py @@ -1,7 +1,8 @@ import time +import threading import docker -from prometheus_client import start_http_server, Gauge, Counter, Info -from concurrent.futures import ThreadPoolExecutor +from prometheus_client import start_http_server, Gauge, Counter +from concurrent.futures import ThreadPoolExecutor, wait, FIRST_EXCEPTION client = docker.from_env() @@ -49,12 +50,19 @@ def collect_one(c): except Exception: pass -def collect(): - containers = client.containers.list() - with ThreadPoolExecutor(max_workers=10) as executor: - executor.map(collect_one, containers) +def collect_loop(): + while True: + try: + containers = client.containers.list() + with ThreadPoolExecutor(max_workers=20) as executor: + executor.map(collect_one, containers) + except Exception: + pass + time.sleep(15) +threading.Thread(target=collect_loop, daemon=True).start() start_http_server(9338) + while True: - collect() - time.sleep(15) + time.sleep(60) +