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) remote_addr = Column(String)
fqdn = Column(String) fqdn = Column(String)
result = Column(postgresql.JSONB) result = Column(postgresql.JSONB)
response_time_ms = Column(Integer)

View file

@ -7,6 +7,7 @@ import socket
import sys import sys
import traceback import traceback
import typing import typing
from time import time
import sqlalchemy import sqlalchemy
import sqlalchemy.exc import sqlalchemy.exc
@ -215,6 +216,7 @@ def handle_database_error(error: Exception) -> tuple[str, int]:
@app.route("/") @app.route("/")
def index() -> str | Response: def index() -> str | Response:
"""Index page.""" """Index page."""
t0 = time()
database.session.execute("SELECT 1") database.session.execute("SELECT 1")
q = request.args.get("q") q = request.args.get("q")
if q and q.strip(): if q and q.strip():
@ -246,6 +248,7 @@ def index() -> str | Response:
remote_addr=remote_addr, remote_addr=remote_addr,
fqdn=socket.getfqdn(remote_addr) if remote_addr else None, fqdn=socket.getfqdn(remote_addr) if remote_addr else None,
result=result, result=result,
response_time_ms=int((time() - t0) * 1000),
) )
database.session.add(log) database.session.add(log)
database.session.commit() database.session.commit()