Commit 8b141fec authored by ale's avatar ale
Browse files

Add a --one-shot option to run all probes sequentially

Prints the results at the end.
parent c651c009
Pipeline #7985 passed with stages
in 1 minute and 47 seconds
import logging
import signal
import time
from flask import Flask, render_template, abort, request
from flask import Flask, render_template, abort
from cheroot.wsgi import Server, PathInfoDispatcher
......@@ -10,21 +10,23 @@ try:
except ImportError:
has_prometheus = False
from ai_diagnostics.driver import Results, PeriodicExecutor
from ai_diagnostics.driver import Results, PeriodicExecutor, LinearExecutor
from ai_diagnostics.config import load_config
app = Flask(__name__)
def create_app(config={}):
def _load_probes():
if 'PROBES' in app.config:
probes = app.config['PROBES']
probes = load_config(app.config['PROBES_CONFIG_DIR'])
return probes
def create_app(config={}):
probes = _load_probes()
probe_interval = app.config.get('PROBE_INTERVAL_SECS', 900)
app.results = Results(
max_age=app.config.get('RESULTS_MAX_AGE', probe_interval * 3))
......@@ -88,25 +90,37 @@ def main():
help='TCP port to listen on (default %(default)s)')
parser.add_argument('--interval', metavar='SECONDS', type=int, default=900,
help='interval between probe runs (default %(default)s secs)')
parser.add_argument('--one-shot', action='store_true',
help='run all probes just once and exit')
args = parser.parse_args()
# Create the application and start the CherryPY WSGI server.
app, cleanup = create_app({
'PROBES_CONFIG_DIR': args.config,
'PROBE_INTERVAL_SECS': args.interval,
if args.one_shot:
probes = _load_probes()
results = Results()
LinearExecutor(results, probes).run()
for k, v in results.get_results().items():
print(f'{k} {v}')
# Create the application and start the CherryPY WSGI server.
flask_app, cleanup = create_app()
if has_prometheus:
app = PathInfoDispatcher({
flask_app = PathInfoDispatcher({
'/metrics': make_wsgi_app(),
'/': app,
'/': flask_app,
server = Server(
(args.addr, args.port),
......@@ -122,7 +122,6 @@ class PeriodicExecutor(object):
def __init__(self, results, probes, interval_secs=600):
self.results = results
#self.probes = probes
self.threads = [
_PeriodicWorker(probe, results, interval_secs)
for probe in probes]
......@@ -134,3 +133,15 @@ class PeriodicExecutor(object):
for t in self.threads:
class LinearExecutor(object):
def __init__(self, results, probes):
self.results = results
self.probes = probes
def run(self):
for probe in self.probes:'%s: executing', probe)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment