From 15c072bb01d0eaf2cef26f287379039600ab1f33 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 6 Sep 2024 16:24:05 +0200 Subject: [PATCH 1/4] Replace temperature display by query frequency Signed-off-by: DL6ER --- scripts/pi-hole/js/footer.js | 73 +++++++--------------------------- scripts/pi-hole/js/index.js | 3 +- scripts/pi-hole/lua/sidebar.lp | 2 +- 3 files changed, 17 insertions(+), 61 deletions(-) diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 440a1054..201037d4 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,24 @@ function initCheckboxRadioStyle() { } } -var systemTimer, sensorsTimer, versionTimer; +var systemTimer, versionTimer; function updateInfo() { updateSystemInfo(); - updateSensorsInfo(); updateVersionInfo(); updateFtlInfo(); checkBlocking(); } +function updateQueryFrequency(intl, frequency) { + $("#query_frequency") + .html( + '  ' + + intl.format(parseFloat(frequency)) + + " q/s" + ) + .attr("title", "Queries per second"); +} + var ftlinfoTimer = null; function updateFtlInfo() { $.ajax({ @@ -250,7 +258,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 +300,7 @@ function updateSystemInfo() { var color; color = percentRAM > 75 ? "text-red" : "text-green-light"; $("#memory").html( - '  Memory usage: ' + percentRAM.toFixed(1) + @@ -315,7 +323,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 +382,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


-
+

From e2b9771f0521b73eae1bf8f2a8e61e62c555c2f7 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 7 Sep 2024 06:25:27 +0200 Subject: [PATCH 2/4] Convert q/s to q/m if there aren't all that many queries on this Pi-hole Signed-off-by: DL6ER --- scripts/pi-hole/js/footer.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 201037d4..b9cffcd5 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -234,13 +234,23 @@ function updateInfo() { } function updateQueryFrequency(intl, frequency) { + let freq = parseFloat(frequency); + let unit = "q/s"; + let title = "Queries per second"; + if (freq < 0.5) { + freq *= 60; + unit = "q/m"; + title = "Queries per minute"; + } + $("#query_frequency") .html( - '  ' + - intl.format(parseFloat(frequency)) + - " q/s" + '  ' + + intl.format(freq) + + " " + + unit ) - .attr("title", "Queries per second"); + .attr("title", title); } var ftlinfoTimer = null; From 3a568b55e19691d0977eec814b88c10f461cf494 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 7 Sep 2024 21:57:11 +0200 Subject: [PATCH 3/4] Dynamically determine number of QPS fraction digits based on the value itself Signed-off-by: DL6ER --- scripts/pi-hole/js/footer.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index b9cffcd5..9b959475 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -243,10 +243,21 @@ function updateQueryFrequency(intl, frequency) { title = "Queries per minute"; } + // 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( '  ' + - intl.format(freq) + + freqFormatted + " " + unit ) From c6fbdfcdffcd5145bffe6deaed03d9220a686c59 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 9 Sep 2024 21:40:42 +0200 Subject: [PATCH 4/4] Queries/minute as default unit. Switching to Queries/second if more than 100 queries are received per minute (~ 1.6q/s) Signed-off-by: DL6ER --- scripts/pi-hole/js/footer.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 9b959475..969fe681 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -234,13 +234,13 @@ function updateInfo() { } function updateQueryFrequency(intl, frequency) { - let freq = parseFloat(frequency); - let unit = "q/s"; - let title = "Queries per second"; - if (freq < 0.5) { - freq *= 60; - unit = "q/m"; - title = "Queries per minute"; + 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