Development
This commit is contained in:
parent
6503f26197
commit
b38c199baf
3 changed files with 20 additions and 17 deletions
|
|
@ -141,12 +141,6 @@
|
|||
{"type": "grid_value", "text": "%DNS_STAT_FORWARDED%"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"cells": [
|
||||
{"type": "grid_label", "text": "Authoritative Answers"},
|
||||
{"type": "grid_value", "text": "%DNS_STAT_AUTH%"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"cells": [
|
||||
{"type": "grid_label", "text": "TCP Peak"},
|
||||
|
|
|
|||
|
|
@ -57,19 +57,19 @@
|
|||
"type": "stat_card",
|
||||
"label": "DNS Queries",
|
||||
"value": "%DNS_STAT_QUERIES%",
|
||||
"sub": "since %DNS_METRICS_SINCE%"
|
||||
"sub": "%DNS_PERIOD_LABEL%"
|
||||
},
|
||||
{
|
||||
"type": "stat_card",
|
||||
"label": "DNS Cache Hits",
|
||||
"value": "%DNS_STAT_HITS% (%DNS_STAT_HIT_RATE%)",
|
||||
"sub": "all time"
|
||||
"sub": "%DNS_PERIOD_LABEL%"
|
||||
},
|
||||
{
|
||||
"type": "stat_card",
|
||||
"label": "Queries Blocked",
|
||||
"value": "%STAT_BLOCKED_ALLTIME%",
|
||||
"sub": "all time",
|
||||
"sub": "%DNS_PERIOD_LABEL%",
|
||||
"variant": "warning",
|
||||
"data_requirement": "HAS_QUERY_LOGGING"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -6,7 +6,16 @@ import factory
|
|||
from pages.ddns.view import public_ip_info
|
||||
from pages.dhcpleases.view import live_dhcp_leases
|
||||
|
||||
METRICS_DB = config_utils.DNS_METRICS_DB
|
||||
METRICS_DB = config_utils.DNS_METRICS_DB
|
||||
DNS_QUERIES_DB = config_utils.DNS_QUERIES_DB
|
||||
|
||||
_PERIOD_LABELS = {
|
||||
1: 'last 1 day', 7: 'last 7 days', 30: 'last 30 days',
|
||||
60: 'last 60 days', 90: 'last 90 days', 365: 'last 365 days', 0: 'all time',
|
||||
}
|
||||
|
||||
def _period_label(period):
|
||||
return _PERIOD_LABELS.get(period, 'all time')
|
||||
|
||||
|
||||
def _fmt_since(since_str):
|
||||
|
|
@ -133,9 +142,6 @@ def load_dns_metrics(period=0):
|
|||
return empty
|
||||
|
||||
|
||||
DNS_QUERIES_DB = config_utils.DNS_QUERIES_DB
|
||||
|
||||
|
||||
def has_query_logging(cfg):
|
||||
return any(v.get('dnsmasq_log_queries') for v in cfg.get('vlans', []))
|
||||
|
||||
|
|
@ -202,14 +208,15 @@ def client_activity_table():
|
|||
return no_data
|
||||
|
||||
|
||||
def all_time_blocked_display():
|
||||
def blocked_display(period=0):
|
||||
try:
|
||||
import sqlite3
|
||||
if not os.path.exists(DNS_QUERIES_DB):
|
||||
return '-'
|
||||
where = f"WHERE ts >= strftime('%s', 'now', 'localtime', '-{period} days')" if period > 0 else ''
|
||||
con = sqlite3.connect(DNS_QUERIES_DB)
|
||||
row = con.execute(
|
||||
'SELECT SUM(blocked), COUNT(*) FROM dns_queries'
|
||||
f'SELECT SUM(blocked), COUNT(*) FROM dns_queries {where}'
|
||||
).fetchone()
|
||||
con.close()
|
||||
blocked, total = row
|
||||
|
|
@ -247,7 +254,8 @@ def collect_tokens(cfg):
|
|||
tokens = config_utils.collect_layout_tokens(cfg)
|
||||
non_vpn_vlans = [v for v in cfg.get('vlans', []) if not v.get('is_vpn')]
|
||||
dns = cfg.get('upstream_dns', {})
|
||||
dns_stats = load_dns_metrics()
|
||||
period = int(dns.get('metrics_period', 0))
|
||||
dns_stats = load_dns_metrics(period=period)
|
||||
ddns = factory.load_ddns()
|
||||
ip_str, domains_sub, _ = public_ip_info(ddns)
|
||||
|
||||
|
|
@ -263,8 +271,9 @@ def collect_tokens(cfg):
|
|||
tokens['DNS_STAT_HIT_RATE'] = dns_stats['hit_rate']
|
||||
tokens['DNS_STAT_CACHE_EVICTIONS'] = dns_stats['cache_evictions']
|
||||
tokens['DNS_METRICS_SINCE'] = dns_stats['since']
|
||||
tokens['DNS_PERIOD_LABEL'] = _period_label(period)
|
||||
|
||||
tokens['STAT_BLOCKED_ALLTIME'] = all_time_blocked_display()
|
||||
tokens['STAT_BLOCKED_ALLTIME'] = blocked_display(period=period)
|
||||
tokens['HAS_QUERY_LOGGING'] = '1' if has_query_logging(cfg) else ''
|
||||
tokens['BLOCKED_DOMAINS_TABLE'] = blocked_domains_table()
|
||||
tokens['CLIENT_ACTIVITY_TABLE'] = client_activity_table()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue