diff --git a/geocode/model.py b/geocode/model.py index f4861b2..e077688 100644 --- a/geocode/model.py +++ b/geocode/model.py @@ -95,3 +95,4 @@ class LookupLog(Base): remote_addr = Column(String) fqdn = Column(String) result = Column(postgresql.JSONB) + response_time_ms = Column(Integer) diff --git a/lookup.py b/lookup.py index cf4eb59..7f91b80 100755 --- a/lookup.py +++ b/lookup.py @@ -7,6 +7,7 @@ import socket import sys import traceback import typing +from time import time import sqlalchemy import sqlalchemy.exc @@ -215,6 +216,7 @@ def handle_database_error(error: Exception) -> tuple[str, int]: @app.route("/") def index() -> str | Response: """Index page.""" + t0 = time() database.session.execute("SELECT 1") q = request.args.get("q") if q and q.strip(): @@ -246,6 +248,7 @@ def index() -> str | Response: remote_addr=remote_addr, fqdn=socket.getfqdn(remote_addr) if remote_addr else None, result=result, + response_time_ms=int((time() - t0) * 1000), ) database.session.add(log) database.session.commit()