Shared default config (->#119)

This commit is contained in:
Arseniy Kuznetsov
2024-03-17 14:36:50 +01:00
parent eff2d2b39b
commit 64b91ec829
10 changed files with 168 additions and 87 deletions

View File

@@ -77,7 +77,7 @@ class CollectorHandler:
# overall scrape duration
total_scrape_timeout_event = Event()
total_scrape_timer = Timer(config_handler.system_entry().total_max_scrape_duration, timeout, args=(total_scrape_timeout_event,))
total_scrape_timer = Timer(config_handler.system_entry.total_max_scrape_duration, timeout, args=(total_scrape_timeout_event,))
total_scrape_timer.start()
with ThreadPoolExecutor(max_workers=max_worker_threads) as executor:
@@ -94,7 +94,7 @@ class CollectorHandler:
# Duration of individual scrapes
scrape_timeout_event = Event()
scrape_timer = Timer(config_handler.system_entry().max_scrape_duration, timeout, args=(scrape_timeout_event,))
scrape_timer = Timer(config_handler.system_entry.max_scrape_duration, timeout, args=(scrape_timeout_event,))
scrape_timer.start()
futures[executor.submit(self.collect_router_entry_async, router_entry, scrape_timeout_event, total_scrape_timeout_event)] = scrape_timer
@@ -117,8 +117,8 @@ class CollectorHandler:
# all other collectors
# Check whether to run in parallel by looking at the mktxp system configuration
parallel = config_handler.system_entry().fetch_routers_in_parallel
max_worker_threads = config_handler.system_entry().max_worker_threads
parallel = config_handler.system_entry.fetch_routers_in_parallel
max_worker_threads = config_handler.system_entry.max_worker_threads
if parallel:
yield from self.collect_async(max_worker_threads=max_worker_threads)
else:
@@ -128,9 +128,9 @@ class CollectorHandler:
def _valid_collect_interval(self):
now = datetime.now().timestamp()
diff = now - self.last_collect_timestamp
if diff < config_handler.system_entry().minimal_collect_interval:
if config_handler.system_entry().verbose_mode:
print(f'An attemp to collect metrics within minimal metrics collection interval: {diff} < {config_handler.system_entry().minimal_collect_interval}')
if diff < config_handler.system_entry.minimal_collect_interval:
if config_handler.system_entry.verbose_mode:
print(f'An attemp to collect metrics within minimal metrics collection interval: {diff} < {config_handler.system_entry.minimal_collect_interval}')
print('deferring..')
return False

View File

@@ -36,8 +36,8 @@ class ExportProcessor:
def start():
REGISTRY.register(CollectorHandler(RouterEntriesHandler(), CollectorRegistry()))
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f'{current_time} Running HTTP metrics server on: {config_handler.system_entry().listen}')
serve(make_wsgi_app(), listen = config_handler.system_entry().listen)
print(f'{current_time} Running HTTP metrics server on: {config_handler.system_entry.listen}')
serve(make_wsgi_app(), listen = config_handler.system_entry.listen)
class OutputProcessor:
''' Base CLI Processing

View File

@@ -59,7 +59,7 @@ class RouterAPIConnection:
ssl_verify = self.config_entry.ssl_certificate_verify,
ssl_context = ctx)
self.connection.socket_timeout = config_handler.system_entry().socket_timeout
self.connection.socket_timeout = config_handler.system_entry.socket_timeout
self.api = None
def is_connected(self):
@@ -92,11 +92,11 @@ class RouterAPIConnection:
def _in_connect_timeout(self, connect_timestamp):
connect_delay = self._connect_delay()
if (connect_timestamp - self.last_failure_timestamp) < connect_delay:
if config_handler.system_entry().verbose_mode:
if config_handler.system_entry.verbose_mode:
print(f'{self.router_name}@{self.config_entry.hostname}: in connect timeout, {int(connect_delay - (connect_timestamp - self.last_failure_timestamp))}secs remaining')
print(f'Successive failure count: {self.successive_failure_count}')
return True
if config_handler.system_entry().verbose_mode:
if config_handler.system_entry.verbose_mode:
print(f'{self.router_name}@{self.config_entry.hostname}: OK to connect')
if self.last_failure_timestamp > 0:
print(f'Seconds since last failure: {connect_timestamp - self.last_failure_timestamp}')
@@ -104,7 +104,7 @@ class RouterAPIConnection:
return False
def _connect_delay(self):
mktxp_entry = config_handler.system_entry()
mktxp_entry = config_handler.system_entry
connect_delay = (1 + self.successive_failure_count / mktxp_entry.delay_inc_div) * mktxp_entry.initial_delay_on_failure
return connect_delay if connect_delay < mktxp_entry.max_delay_on_failure else mktxp_entry.max_delay_on_failure