Development

This commit is contained in:
Matthew Grotke 2026-06-09 21:49:29 -04:00
parent e4629fd164
commit 0806656d68
2 changed files with 12 additions and 11 deletions

View file

@ -8,29 +8,28 @@ import mod_dns_queries
from pages.ddns.view import public_ip_info
from pages.dhcpleases.view import live_dhcp_leases
METRICS_DB = f'{config_utils.CONFIGS_DIR}/.dns-metrics2'
METRICS_DB = f'{config_utils.CONFIGS_DIR}/.dns-metrics'
def _fmt_since(since_str):
try:
dt = datetime.strptime(since_str, '%Y-%m-%d %H:%M:%S')
dt = datetime.strptime(since_str, '%Y-%m-%d')
now = datetime.now()
rel = config_utils.relative_time(int(dt.timestamp()), int(now.timestamp()))
if dt.date() == now.date():
return f'Today at {dt.strftime("%H:%M")} ({rel} ago)'
return 'Today'
return f'{dt.strftime("%Y-%m-%d")} ({rel} ago)'
except Exception:
return since_str
def _fmt_updated(updated_str):
def _fmt_updated(updated_ts):
try:
dt = datetime.strptime(updated_str, '%Y-%m-%d %H:%M:%S')
now = datetime.now()
rel = config_utils.relative_time(int(dt.timestamp()), int(now.timestamp()))
rel = config_utils.relative_time(int(updated_ts), int(now.timestamp()))
return f'{rel} ago'
except Exception:
return updated_str
return '-'
def _dns_providers_table(servers):
@ -79,7 +78,7 @@ def load_dns_metrics(period=0):
con.execute('PRAGMA journal_mode=WAL')
row = con.execute(f'''
SELECT
MIN(date), MAX(date),
MIN(date), MAX(last_updated),
SUM(queries_forwarded), SUM(queries_answered_locally),
SUM(queries_authoritative), SUM(cache_reused), MAX(tcp_hwm)
FROM daily_totals {where}