Use a threadpool to this faster; increase resolution of the collectd graph.
This commit is contained in:
parent
20e22a5005
commit
06d2517c67
1 changed files with 34 additions and 29 deletions
|
@ -6,6 +6,7 @@ Reports what percentage of fedmsg endpoints are bound and ready.
|
|||
|
||||
import base64
|
||||
import collections
|
||||
import multiprocessing.pool
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
|
@ -18,18 +19,17 @@ expected = '/wAAAAAAAAABfw=='
|
|||
|
||||
for_collectd = 'verbose' not in sys.argv
|
||||
|
||||
active = collections.defaultdict(list)
|
||||
inactive = collections.defaultdict(list)
|
||||
|
||||
pool = multiprocessing.pool.ThreadPool(10)
|
||||
|
||||
def info(content="\n"):
|
||||
if not for_collectd:
|
||||
sys.stdout.write(content)
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def do_scan():
|
||||
active = collections.defaultdict(list)
|
||||
inactive = collections.defaultdict(list)
|
||||
|
||||
for i, item in enumerate(config['endpoints'].items()):
|
||||
def scan_one(item):
|
||||
name, endpoints = item
|
||||
for endpoint in endpoints:
|
||||
if not endpoint.startswith('tcp://'):
|
||||
|
@ -52,6 +52,11 @@ def do_scan():
|
|||
if connection:
|
||||
connection.close()
|
||||
|
||||
|
||||
def scan_all():
|
||||
|
||||
pool.map(scan_one, config['endpoints'].items())
|
||||
|
||||
info()
|
||||
|
||||
if 'verbose' in sys.argv:
|
||||
|
@ -101,13 +106,13 @@ def do_scan():
|
|||
return value
|
||||
|
||||
if not for_collectd:
|
||||
do_scan()
|
||||
scan_all()
|
||||
else:
|
||||
interval = 10
|
||||
interval = 5
|
||||
host = socket.getfqdn()
|
||||
while True:
|
||||
start = time.time()
|
||||
value = do_scan()
|
||||
value = scan_all()
|
||||
stop = timestamp = time.time()
|
||||
delta = stop - start
|
||||
output = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue