Development

This commit is contained in:
Matthew Grotke 2026-06-09 21:40:14 -04:00
parent 0983e14de4
commit e4629fd164
4 changed files with 65 additions and 6 deletions

View file

@ -63,7 +63,7 @@ def _dns_providers_table(servers):
)
def load_dns_metrics():
def load_dns_metrics(period=0):
import sqlite3
empty = {
'queries': '-', 'hits': '-', 'hit_rate': '-', 'forwarded': '-',
@ -71,16 +71,20 @@ def load_dns_metrics():
'updated': '-', 'since': '-', 'servers': [],
}
try:
where = (
f"WHERE date >= date('now','localtime','-{period - 1} days')"
if period and period > 0 else ''
)
con = sqlite3.connect(METRICS_DB, timeout=5)
con.execute('PRAGMA journal_mode=WAL')
row = con.execute('''
row = con.execute(f'''
SELECT
MIN(date), MAX(date),
SUM(queries_forwarded), SUM(queries_answered_locally),
SUM(queries_authoritative), SUM(cache_reused), MAX(tcp_hwm)
FROM daily_totals
FROM daily_totals {where}
''').fetchone()
srv_rows = con.execute('''
srv_rows = con.execute(f'''
SELECT
ds.address,
SUM(ds.queries_sent),
@ -90,7 +94,7 @@ def load_dns_metrics():
(SELECT avg_latency_ms FROM daily_servers d2
WHERE d2.address = ds.address AND d2.avg_latency_ms > 0
ORDER BY d2.date DESC LIMIT 1)
FROM daily_servers ds
FROM daily_servers ds {where}
GROUP BY ds.address
ORDER BY SUM(ds.queries_sent) DESC
''').fetchall()