Add DNS cache efficiency metric

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2023-05-11 13:53:01 +02:00
parent eb1cfe2c70
commit c99eca3aee
2 changed files with 16 additions and 8 deletions

View File

@@ -9,19 +9,20 @@
var hostinfoTimer = null; var hostinfoTimer = null;
var cachePieChart = null; var cachePieChart = null;
var cacheSize = 0; var cacheSize = 0,
cacheEntries = 0;
var querytypeids = []; var querytypeids = [];
function updateCachePie(data) { function updateCachePie(data) {
var v = [], var v = [],
c = [], c = [],
k = [], k = [],
i = 0, i = 0;
sum = 0;
// Compute total number of queries // Compute total number of cache entries
cacheEntries = 0;
Object.keys(data).forEach(function (item) { Object.keys(data).forEach(function (item) {
sum += data[item]; cacheEntries += data[item];
}); });
// Sort data by value, put OTHER always as last // Sort data by value, put OTHER always as last
@@ -43,13 +44,12 @@ function updateCachePie(data) {
data = tmp; data = tmp;
// Add empty space to chart // Add empty space to chart
data.empty = cacheSize - sum; data.empty = cacheSize - cacheEntries;
sum = cacheSize;
// Fill chart with data // Fill chart with data
querytypeids = []; querytypeids = [];
Object.keys(data).forEach(function (item) { Object.keys(data).forEach(function (item) {
v.push((100 * data[item]) / sum); v.push((100 * data[item]) / cacheSize);
c.push(item !== "empty" ? THEME_COLORS[i % THEME_COLORS.length] : "#80808040"); c.push(item !== "empty" ? THEME_COLORS[i % THEME_COLORS.length] : "#80808040");
k.push(item); k.push(item);
querytypeids.push(i + 1); querytypeids.push(i + 1);
@@ -155,6 +155,8 @@ function updateMetrics() {
// Set metrics // Set metrics
setMetrics(metrics, "sysinfo-"); setMetrics(metrics, "sysinfo-");
$("#cache-efficiency").text(((100 * cacheEntries) / cacheSize).toFixed(2) + "%");
$("div[id^='sysinfo-metrics-overlay']").hide(); $("div[id^='sysinfo-metrics-overlay']").hide();
// Update every 10 seconds // Update every 10 seconds
clearTimeout(metricsTimer); clearTimeout(metricsTimer);

View File

@@ -174,6 +174,12 @@ mg.include('scripts/pi-hole/lua/header_authenticated.lp','r')
</th> </th>
<td id="sysinfo-dns-cache-size">&nbsp;</td> <td id="sysinfo-dns-cache-size">&nbsp;</td>
</tr> </tr>
<tr>
<th scope="row">
<span title="Percentage of the allocated cache that is currently in use. If this value is very low, it is advisable to reduce the DNS cache size to optimize performance">DNS cache efficiency:</span>
</th>
<td id="cache-efficiency">&nbsp;</td>
</tr>
<tr> <tr>
<th scope="row"> <th scope="row">
<span title="Number of cache insertions">DNS cache insertions:</span> <span title="Number of cache insertions">DNS cache insertions:</span>