This commit is contained in:
24
exporter.py
24
exporter.py
@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user