Commit 77fc2097 authored by ale's avatar ale
Browse files

Store recent errors

parent 6f00a5fc
Pipeline #5416 passed with stages
in 2 minutes and 1 second
......@@ -38,6 +38,7 @@ def create_app(config={}):
def home():
return render_template(
'index.html',
errors=app.results.get_errors(),
results=app.results.get_results(),
)
......@@ -50,7 +51,19 @@ def probe_detail(probe_name):
return render_template(
'details.html',
probe_name=probe_name,
result=result
result=result,
)
@app.route('/errdetail/<probe_ts>/<path:probe_name>')
def probe_error(probe_ts, probe_name):
result = app.results.get_error(probe_name, probe_ts)
if not result:
abort(404)
return render_template(
'details.html',
probe_name=probe_name,
result=result,
)
......
......@@ -46,6 +46,30 @@ class Runner(object):
t.join()
class _ResultLog(object):
"""Keep around a limited number of probe results."""
MAX_SIZE = 100
def __init__(self):
self.results = {}
self.log = []
def add(self, name, timestamp, result):
key = (name, timestamp)
self.results[key] = result
self.log.append(key)
while len(self.log) > self.MAX_SIZE:
del self.results[self.log[0]]
self.log = self.log[1:]
def get(self, name, timestamp):
return self.results[(name, timestamp)]
def get_all(self):
return self.log[::-1]
class Results(object):
"""Result cache that eventually forgets old results.
......@@ -58,6 +82,7 @@ class Results(object):
self.max_age = max_age
self.lock = threading.Lock()
self.results = {}
self.error_log = _ResultLog()
def add(self, name, timestamp, result):
with self.lock:
......@@ -66,6 +91,16 @@ class Results(object):
if timestamp < cur_ts:
return
self.results[name] = (timestamp, result)
if result.get('status') != 'ok':
self.error_log.add(name, timestamp, result)
def get_error(self, name, timestamp):
with self.lock:
return self.error_log.get(name, timestamp)
def get_errors(self):
with self.lock:
return self.error_log.get_all()
def get_results(self):
cutoff = time.time() - self.max_age
......
......@@ -11,4 +11,13 @@
</p>
{% endfor %}
<h3>Recent Errors</h3>
{% for name, timestamp, res in errors %}
<p>
<a href="{{ url_for('probe_error', probe_name=name, probe_ts=timestamp) }}" class="error">
{{ res.timestamp | timefmt }} / <b>{{ res.status | upper }}</b> / {{ name }}</a>
</p>
{% endfor %}
{% endblock %}
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