Start logging response time ms

This commit is contained in:
Edward Betts 2023-12-10 10:41:36 +00:00
parent 8bfe86ee82
commit e65f85becb
2 changed files with 4 additions and 0 deletions

View file

@ -95,3 +95,4 @@ class LookupLog(Base):
remote_addr = Column(String)
fqdn = Column(String)
result = Column(postgresql.JSONB)
response_time_ms = Column(Integer)

View file

@ -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()