This commit is contained in:
24
exporter.py
24
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():
|
||||
def collect_loop():
|
||||
while True:
|
||||
try:
|
||||
containers = client.containers.list()
|
||||
with ThreadPoolExecutor(max_workers=10) as executor:
|
||||
with ThreadPoolExecutor(max_workers=20) as executor:
|
||||
executor.map(collect_one, containers)
|
||||
|
||||
start_http_server(9338)
|
||||
while True:
|
||||
collect()
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(15)
|
||||
|
||||
threading.Thread(target=collect_loop, daemon=True).start()
|
||||
start_http_server(9338)
|
||||
|
||||
while True:
|
||||
time.sleep(60)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user