diff --git a/scripts/pi-hole/js/settings-system.js b/scripts/pi-hole/js/settings-system.js index ebc4f45e..f26516a3 100644 --- a/scripts/pi-hole/js/settings-system.js +++ b/scripts/pi-hole/js/settings-system.js @@ -43,49 +43,35 @@ function updateHostInfo() { }); } -var cacheinfoTimer = null; +// Walk nested objects, create a dash-separated global key and assign the value +// to the corresponding element (add percentage for DNS replies) +function setMetrics(data, prefix) { + for (const [key, val] of Object.entries(data)) { + if (typeof val === "object") { + setMetrics(val, prefix + key + "-"); + } else if (prefix === "sysinfo-dns-replies-") { + // Compute and display percentage of DNS replies in addition to the absolute value + $("#" + prefix + key).text(val + " (" + ((100 * val) / data.sum).toFixed(1) + "%)"); + } else { + $("#" + prefix + key).text(val); + } + } +} + +var metricsTimer = null; // eslint-disable-next-line no-unused-vars -function updateCacheInfo() { +function updateMetrics() { $.ajax({ - url: "/api/info/cache", + url: "/api/info/metrics", }) .done(function (data) { - var cache = data.cache; - $("#sysinfo-cache-size").text(cache.size); - $("#sysinfo-cache-inserted").text(cache.inserted); - $("#sysinfo-cache-evicted").text(cache.evicted); - $("#sysinfo-cache-expired").text(cache.expired); - $("#sysinfo-cache-immortal").text(cache.immortal); - $("#sysinfo-cache-valid-a").text(cache.valid.a); - $("#sysinfo-cache-valid-aaaa").text(cache.valid.aaaa); - $("#sysinfo-cache-valid-cname").text(cache.valid.cname); - $("#sysinfo-cache-valid-srv").text(cache.valid.srv); - $("#sysinfo-cache-valid-ds").text(cache.valid.ds); - $("#sysinfo-cache-valid-dnskey").text(cache.valid.dnskey); - $("#sysinfo-cache-valid-other").text(cache.valid.other); + var metrics = data.metrics; + setMetrics(metrics, "sysinfo-"); - var total = - cache.optimized + cache.local + cache.auth + cache.extra.unanswered + cache.extra.forwarded; - $("#sysinfo-replies-optimized").text( - cache.optimized + " (" + ((100 * cache.optimized) / total).toFixed(1) + "%)" - ); - $("#sysinfo-replies-local").text( - cache.local + " (" + ((100 * cache.local) / total).toFixed(1) + "%)" - ); - $("#sysinfo-replies-auth").text( - cache.auth + " (" + ((100 * cache.auth) / total).toFixed(1) + "%)" - ); - $("#sysinfo-replies-extra-unanswered").text( - cache.extra.unanswered + " (" + ((100 * cache.extra.unanswered) / total).toFixed(1) + "%)" - ); - $("#sysinfo-replies-extra-forwarded").text( - cache.extra.forwarded + " (" + ((100 * cache.extra.forwarded) / total).toFixed(1) + "%)" - ); - - $("#sysinfo-dns-overlay").hide(); + $("#sysinfo-metrics-overlay").hide(); // Update every 10 seconds - clearTimeout(cacheinfoTimer); - cacheinfoTimer = setTimeout(updateCacheInfo, 10000); + clearTimeout(metricsTimer); + metricsTimer = setTimeout(updateMetrics, 10000); }) .fail(function (data) { apiFailure(data); diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js index c64d4f0f..5be7fda0 100644 --- a/scripts/pi-hole/js/settings.js +++ b/scripts/pi-hole/js/settings.js @@ -5,11 +5,11 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global updateHostInfo:false, updateCacheInfo:false, createDynamicConfigTabs:false */ +/* global updateHostInfo:false, updateMetrics:false, createDynamicConfigTabs:false */ $(function () { updateHostInfo(); - updateCacheInfo(); + updateMetrics(); createDynamicConfigTabs(); }); diff --git a/settings.php b/settings.php index dec66e34..55269771 100644 --- a/settings.php +++ b/settings.php @@ -129,7 +129,7 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array('sysadmin', 'dns', 'dhcp
| + DHCPDISCOVER: + | ++ |
|---|---|
| + DHCPOFFER: + | ++ |
| + DHCPREQUEST: + | ++ |
| + DHCPACK: + | ++ |
| + DHCPNAK: + | ++ |
| + DHCPDECLINE: + | ++ |
| + DHCPINFORM: + | ++ |
| + DHCPRELEASE: + | ++ |
| + DHCPNOANSWER: + | ++ |
| + BOOTP: + | ++ |
| + PXE: + | ++ |
| + Allocated / pruned IPv4 leases: + | +/ + + | +
| + Allocated / pruned IPv6 leases: + | +/ + + |