diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index d5e7b684..9186f973 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -17,7 +17,6 @@ const REFRESH_INTERVAL = { blocking: 10000, // 10 sec (all pages, sidebar) metrics: 10000, // 10 sec (settings page) system: 20000, // 20 sec (all pages, sidebar) - sensors: 20000, // 20 sec (all pages, sidebar) query_types: 60000, // 1 min (dashboard) upstreams: 60000, // 1 min (dashboard) top_lists: 60000, // 1 min (dashboard) @@ -226,15 +225,45 @@ function initCheckboxRadioStyle() { } } -var systemTimer, sensorsTimer, versionTimer; +var systemTimer, versionTimer; function updateInfo() { updateSystemInfo(); - updateSensorsInfo(); updateVersionInfo(); updateFtlInfo(); checkBlocking(); } +function updateQueryFrequency(intl, frequency) { + let freq = parseFloat(frequency) * 60; + let unit = "q/min"; + let title = "Queries per minute"; + if (freq > 100) { + freq /= 60; + unit = "q/s"; + title = "Queries per second"; + } + + // Determine number of fraction digits based on the frequency + // - 0 fraction digits for frequencies > 10 + // - 1 fraction digit for frequencies between 1 and 10 + // - 2 fraction digits for frequencies < 1 + const fractionDigits = freq > 10 ? 0 : freq < 1 ? 2 : 1; + const userLocale = navigator.language || "en-US"; + const freqFormatted = new Intl.NumberFormat(userLocale, { + minimumFractionDigits: fractionDigits, + maximumFractionDigits: fractionDigits, + }).format(freq); + + $("#query_frequency") + .html( + '  ' + + freqFormatted + + " " + + unit + ) + .attr("title", title); +} + var ftlinfoTimer = null; function updateFtlInfo() { $.ajax({ @@ -250,7 +279,7 @@ function updateFtlInfo() { $("#num_gravity").text(intl.format(database.gravity)); $("#num_allowed").text(intl.format(database.domains.allowed)); $("#num_denied").text(intl.format(database.domains.denied)); - + updateQueryFrequency(intl, ftl.query_frequency); $("#sysinfo-cpu-ftl").text("(" + ftl["%cpu"].toFixed(1) + "% used by FTL)"); $("#sysinfo-ram-ftl").text("(" + ftl["%mem"].toFixed(1) + "% used by FTL)"); $("#sysinfo-pid-ftl").text(ftl.pid); @@ -292,7 +321,7 @@ function updateSystemInfo() { var color; color = percentRAM > 75 ? "text-red" : "text-green-light"; $("#memory").html( - '  Memory usage: ' + percentRAM.toFixed(1) + @@ -315,7 +344,7 @@ function updateSystemInfo() { color = system.cpu.load.percent[0] > 100 ? "text-red" : "text-green-light"; $("#cpu").html( - '  CPU: ' + system.cpu.load.percent[0].toFixed(1) + @@ -374,59 +403,6 @@ function updateSystemInfo() { }); } -function updateSensorsInfo() { - $.ajax({ - url: "/api/info/sensors", - }) - .done(function (data) { - var unit = "°" + data.sensors.unit; - if (data.sensors.unit === "°K") { - unit = data.sensors.unit; - } - - if (data.sensors.cpu_temp !== null) { - var temp = data.sensors.cpu_temp.toFixed(1) + " " + unit; - var color = - data.sensors.cpu_temp > data.sensors.hot_limit - ? "text-red fa-temperature-high" - : "text-green-light fa-temperature-low"; - $("#temperature").html( - '  Temp: ' + temp - ); - } else - $("#temperature").html( - '  Temp: N/A' - ); - - // Get a text listing of all sensors - let sensorlist = "Available sensors:\n"; - $.each(data.sensors.list, function (index, hwmon) { - sensorlist += "- " + hwmon.name + " (" + hwmon.source + "):\n"; - $.each(hwmon.temps, function (index, temp) { - sensorlist += - " - " + - temp.name + - ": " + - temp.value.toFixed(1) + - unit + - " (max: " + - (temp.max === null ? "N/A" : temp.max.toFixed(1) + unit) + - ", crit: " + - (temp.crit === null ? "N/A" : temp.crit.toFixed(1) + unit) + - ")\n"; - }); - }); - $("#temperature").prop("title", sensorlist); - - // Update every 20 seconds - clearTimeout(sensorsTimer); - sensorsTimer = utils.setTimer(updateSensorsInfo, REFRESH_INTERVAL.sensors); - }) - .fail(function (data) { - apiFailure(data); - }); -} - function apiFailure(data) { if (data.status === 401) { // Unauthorized, reload page diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 2ea6e44f..28910f3f 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -5,7 +5,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global utils:false, Chart:false, apiFailure:false, THEME_COLORS:false, customTooltips:false, htmlLegendPlugin:false,doughnutTooltip:false, ChartDeferred:false, REFRESH_INTERVAL: false */ +/* global utils:false, Chart:false, apiFailure:false, THEME_COLORS:false, customTooltips:false, htmlLegendPlugin:false,doughnutTooltip:false, ChartDeferred:false, REFRESH_INTERVAL: false, updateQueryFrequency: false */ // Define global variables var timeLineChart, clientsChart; @@ -415,6 +415,7 @@ function updateSummaryData(runOnce = false) { var formattedPercentage = utils.toPercent(data.queries.percent_blocked, 1); $("span#percent_blocked").text(formattedPercentage); $("span#gravity_size").text(intl.format(parseInt(data.gravity.domains_being_blocked, 10))); + updateQueryFrequency(intl, data.queries.frequency); const lastupdate = parseInt(data.gravity.last_update, 10); var updatetxt = "Lists were never updated"; diff --git a/scripts/pi-hole/lua/sidebar.lp b/scripts/pi-hole/lua/sidebar.lp index 578e8b94..3e9dafa2 100644 --- a/scripts/pi-hole/lua/sidebar.lp +++ b/scripts/pi-hole/lua/sidebar.lp @@ -18,7 +18,7 @@

Status


-
+