Update exporter.py
All checks were successful
Build / build (push) Successful in 5s

This commit is contained in:
2026-03-18 12:28:58 +03:00
parent 54336fd622
commit 6e5342d2a9

View File

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