diff options
| author | Alexandre Flament <alex@al-f.net> | 2020-12-03 10:31:44 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-03 10:31:44 +0100 |
| commit | 89fbb85d454959be725cd4ca19c36c31d05d3289 (patch) | |
| tree | 7ef098d4630c5416aad58f0d3ce5abb27390423f /searx/webapp.py | |
| parent | 6b5a57882242f24f867b6aa14b79b514720c6d83 (diff) | |
| parent | 64cccae99e625f3ebd879f94797decd0d824608d (diff) | |
Merge pull request #2332 from dalf/metrology-errors
[enh] record exception details per engine
Diffstat (limited to 'searx/webapp.py')
| -rwxr-xr-x | searx/webapp.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/searx/webapp.py b/searx/webapp.py index e73322a77..ace5a12dc 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -79,6 +79,7 @@ from searx.plugins.oa_doi_rewrite import get_doi_resolver from searx.preferences import Preferences, ValidationException, LANGUAGE_CODES from searx.answerers import answerers from searx.poolrequests import get_global_proxies +from searx.metrology.error_recorder import errors_per_engines # serve pages with HTTP/1.1 @@ -943,6 +944,34 @@ def stats(): ) +@app.route('/stats/errors', methods=['GET']) +def stats_errors(): + result = {} + engine_names = list(errors_per_engines.keys()) + engine_names.sort() + for engine_name in engine_names: + error_stats = errors_per_engines[engine_name] + sent_search_count = max(engines[engine_name].stats['sent_search_count'], 1) + sorted_context_count_list = sorted(error_stats.items(), key=lambda context_count: context_count[1]) + r = [] + percentage_sum = 0 + for context, count in sorted_context_count_list: + percentage = round(20 * count / sent_search_count) * 5 + percentage_sum += percentage + r.append({ + 'filename': context.filename, + 'function': context.function, + 'line_no': context.line_no, + 'code': context.code, + 'exception_classname': context.exception_classname, + 'log_message': context.log_message, + 'log_parameters': context.log_parameters, + 'percentage': percentage, + }) + result[engine_name] = sorted(r, reverse=True, key=lambda d: d['percentage']) + return jsonify(result) + + @app.route('/robots.txt', methods=['GET']) def robots(): return Response("""User-agent: * |