Development
This commit is contained in:
parent
0983e14de4
commit
e4629fd164
4 changed files with 65 additions and 6 deletions
|
|
@ -1,7 +1,34 @@
|
|||
import json
|
||||
import config_utils
|
||||
import factory
|
||||
from pages.overview.view import load_dns_metrics, _dns_providers_table
|
||||
|
||||
_PERIOD_OPTIONS = [
|
||||
(1, '1 Day'),
|
||||
(7, '7 Days'),
|
||||
(30, '30 Days'),
|
||||
(60, '60 Days'),
|
||||
(90, '90 Days'),
|
||||
(365, '365 Days'),
|
||||
(0, 'All Time'),
|
||||
]
|
||||
|
||||
|
||||
def _period_selector_html(current_period):
|
||||
opts = ''.join(
|
||||
f'<option value="{v}"{" selected" if v == current_period else ""}>{label}</option>'
|
||||
for v, label in _PERIOD_OPTIONS
|
||||
)
|
||||
return (
|
||||
'<form method="post" action="/action/dnsserver/metrics_period_save"'
|
||||
' style="display:flex;align-items:center;gap:0.75rem;margin-bottom:1rem">'
|
||||
'<label class="form-label" style="margin:0;white-space:nowrap">Period</label>'
|
||||
f'<select name="metrics_period" class="form-input" style="width:auto"'
|
||||
f' onchange="this.form.submit()">{opts}</select>'
|
||||
f'<input type="hidden" name="config_hash" value="{factory.e(config_utils.config_hash())}"/>'
|
||||
'</form>'
|
||||
)
|
||||
|
||||
|
||||
def collect_tokens(cfg):
|
||||
tokens = config_utils.collect_layout_tokens(cfg)
|
||||
|
|
@ -11,7 +38,10 @@ def collect_tokens(cfg):
|
|||
tokens['DNS_CACHE_SIZE'] = str(dns.get('cache_size', '-'))
|
||||
tokens['DNS_UPSTREAM_SERVERS_JSON'] = json.dumps(servers)
|
||||
|
||||
dns_stats = load_dns_metrics()
|
||||
period = int(dns.get('metrics_period', 0))
|
||||
dns_stats = load_dns_metrics(period=period)
|
||||
|
||||
tokens['DNS_PERIOD_SELECTOR'] = _period_selector_html(period)
|
||||
tokens['DNS_METRICS_SINCE'] = dns_stats['since']
|
||||
tokens['DNS_METRICS_UPDATED'] = dns_stats['updated']
|
||||
tokens['DNS_STAT_QUERIES'] = dns_stats['queries']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue