From ac1cdd56aec9b616d583b8b38887213c771b0e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Mon, 3 Sep 2018 19:32:03 +0200 Subject: Track ServerQuery latency --- QueryServer.py | 8 +++++++- templates/server_html.jinja | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/QueryServer.py b/QueryServer.py index 52e4aa0..fb2efd1 100755 --- a/QueryServer.py +++ b/QueryServer.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +import time + # Time to live for caching. 0 to disable caching CACHE_TTL = 15 @@ -71,6 +73,7 @@ class QueryServer(): if gameid in sourcequeryinc: port += 1 + starttime = time.time() conn = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) message = None @@ -89,7 +92,10 @@ class QueryServer(): finally: conn.close() - data = dict() + data = {} + + latency = time.time() - starttime + data['latency'] = int(latency * 1000) # [0]-[3] -> 4*\xFF data['header'] = chr(message[4]) diff --git a/templates/server_html.jinja b/templates/server_html.jinja index 9702300..5b530e5 100644 --- a/templates/server_html.jinja +++ b/templates/server_html.jinja @@ -17,7 +17,7 @@ {% for name, info in servers.items() %}
{% if info['data'] %}
-- cgit v1.2.3