From 0806656d68e4096e89092f43b5f3b3f9ddf571f3 Mon Sep 17 00:00:00 2001 From: Matthew Grotke Date: Tue, 9 Jun 2026 21:49:29 -0400 Subject: [PATCH] Development --- docker/routlin-dash/app/pages/overview/view.py | 15 +++++++-------- routlin/mod_metrics.py | 8 +++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docker/routlin-dash/app/pages/overview/view.py b/docker/routlin-dash/app/pages/overview/view.py index 562e716..73d535f 100644 --- a/docker/routlin-dash/app/pages/overview/view.py +++ b/docker/routlin-dash/app/pages/overview/view.py @@ -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} diff --git a/routlin/mod_metrics.py b/routlin/mod_metrics.py index 98ab669..893bafe 100644 --- a/routlin/mod_metrics.py +++ b/routlin/mod_metrics.py @@ -20,7 +20,7 @@ from datetime import date import mod_shared as shared import mod_validation as validation -DB_FILE = shared.SCRIPT_DIR / ".dns-metrics2" +DB_FILE = shared.SCRIPT_DIR / ".dns-metrics" # =================================================================== @@ -33,6 +33,7 @@ def open_db(): con.executescript(''' CREATE TABLE IF NOT EXISTS daily_totals ( date TEXT PRIMARY KEY, + last_updated INTEGER, queries_forwarded INTEGER NOT NULL DEFAULT 0, queries_answered_locally INTEGER NOT NULL DEFAULT 0, queries_authoritative INTEGER NOT NULL DEFAULT 0, @@ -162,12 +163,13 @@ def update_metrics_db(new_metrics): con.execute(''' INSERT INTO daily_totals( - date, + date, last_updated, queries_forwarded, queries_answered_locally, queries_authoritative, cache_reused, tcp_hwm, tcp_max_allowed, pool_memory_max, dnssec_subqueries_hwm, dnssec_crypto_hwm, dnssec_sig_fails_hwm - ) VALUES (?,?,?,?,?,?,?,?,?,?,?) + ) VALUES (?,strftime('%s','now'),?,?,?,?,?,?,?,?,?,?) ON CONFLICT(date) DO UPDATE SET + last_updated = strftime('%s','now'), queries_forwarded = queries_forwarded + excluded.queries_forwarded, queries_answered_locally = queries_answered_locally + excluded.queries_answered_locally, queries_authoritative = queries_authoritative + excluded.queries_authoritative,