Use new /api/info/metrics endpoint to generate (settings level dependent) metrics on the first tab of the settings page

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2023-02-11 13:39:24 +01:00
parent c8bdc58fb4
commit d4f98b1f60
3 changed files with 151 additions and 92 deletions
+23 -37
View File
@@ -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);
+2 -2
View File
@@ -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();
});
+126 -53
View File
@@ -129,7 +129,7 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array('sysadmin', 'dns', 'dhcp
<div class="col-md-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">DNS Information</h3>
<h3 class="box-title">Server metrics</h3>
</div>
<div class="box-body">
<div class="row">
@@ -147,73 +147,73 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array('sysadmin', 'dns', 'dhcp
<th scope="row">
<span title="Size of the DNS domain cache">DNS cache size:</span>
</th>
<td id="sysinfo-cache-size">&nbsp;</td>
<td id="sysinfo-dns-cache-size">&nbsp;</td>
</tr>
<tr>
<th scope="row">
<span title="Number of cache insertions">DNS cache insertions:</span>
</th>
<td id="sysinfo-cache-inserted">&nbsp;</td>
<td id="sysinfo-dns-cache-inserted">&nbsp;</td>
</tr>
<tr>
<th scope="row">
<span title="Number of cache entries that had to be removed although they are not expired (increase cache size to reduce this number)" lookatme-text="DNS cache evictions:">DNS cache evictions:</span>
</th>
<td id="sysinfo-cache-evicted">&nbsp;</td>
<td id="sysinfo-dns-cache-evicted">&nbsp;</td>
</tr>
<tr>
<th scope="row">
DNS cache expiries:
</th>
<td id="sysinfo-cache-expired">&nbsp;</td>
<td id="sysinfo-dns-cache-expired">&nbsp;</td>
</tr>
<tr>
<th scope="row">
Immortal DNS cache entries:
</th>
<td id="sysinfo-cache-immortal">&nbsp;</td>
<td id="sysinfo-dns-cache-immortal">&nbsp;</td>
</tr>
<tr>
<tr class="settings-level-2">
<th scope="row">
Valid A records in cache:
</th>
<td id="sysinfo-cache-valid-a">&nbsp;</td>
<td id="sysinfo-dns-cache-content-a">&nbsp;</td>
</tr>
<tr>
<tr class="settings-level-2">
<th scope="row">
Valid AAAA records in cache:
</th>
<td id="sysinfo-cache-valid-aaaa">&nbsp;</td>
<td id="sysinfo-dns-cache-content-aaaa">&nbsp;</td>
</tr>
<tr>
<tr class="settings-level-2">
<th scope="row">
Valid CNAME records in cache:
</th>
<td id="sysinfo-cache-valid-cname">&nbsp;</td>
<td id="sysinfo-dns-cache-content-cname">&nbsp;</td>
</tr>
<tr>
<tr class="settings-level-2">
<th scope="row">
Valid SRV records in cache:
</th>
<td id="sysinfo-cache-valid-srv">&nbsp;</td>
<td id="sysinfo-dns-cache-content-srv">&nbsp;</td>
</tr>
<tr>
<tr class="settings-level-2">
<th scope="row">
Valid DS records in cache:
</th>
<td id="sysinfo-cache-valid-ds">&nbsp;</td>
<td id="sysinfo-dns-cache-content-ds">&nbsp;</td>
</tr>
<tr>
<tr class="settings-level-2">
<th scope="row">
Valid DNSKEY records in cache:
</th>
<td id="sysinfo-cache-valid-dnskey">&nbsp;</td>
<td id="sysinfo-dns-cache-content-dnskey">&nbsp;</td>
</tr>
<tr>
<tr class="settings-level-2">
<th scope="row">
Other valid records in cache:
</th>
<td id="sysinfo-cache-valid-other">&nbsp;</td>
<td id="sysinfo-dns-cache-content-other">&nbsp;</td>
</tr>
</tbody>
</table>
@@ -237,31 +237,130 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array('sysadmin', 'dns', 'dhcp
<th scope="row">
<span>Local replies:</span>
</th>
<td id="sysinfo-replies-local">&nbsp;</td>
<td id="sysinfo-dns-replies-local">&nbsp;</td>
</tr>
<tr>
<th scope="row">
Forwarded queries:
</th>
<td id="sysinfo-replies-extra-forwarded">&nbsp;</td>
<td id="sysinfo-dns-replies-forwarded">&nbsp;</td>
</tr>
<tr>
<th scope="row">
Unanswered queries:
</th>
<td id="sysinfo-replies-extra-unanswered">&nbsp;</td>
<td id="sysinfo-dns-replies-unanswered">&nbsp;</td>
</tr>
<tr>
<th scope="row">
<span>Cache optimizer replies:</span>
</th>
<td id="sysinfo-replies-optimized">&nbsp;</td>
<td id="sysinfo-dns-replies-optimized">&nbsp;</td>
</tr>
<tr>
<tr class="settings-level-2">
<th scope="row">
<span>Authoritative replies:</span>
</th>
<td id="sysinfo-replies-auth">&nbsp;</td>
<td id="sysinfo-dns-replies-auth">&nbsp;</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-12 settings-level-2">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">DHCP server</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-lg-12">
<table class="table table-striped table-bordered nowrap">
<tbody>
<tr class="settings-level-2">
<th scope="row">
<span>DHCPDISCOVER:</span>
</th>
<td id="sysinfo-dhcp-discover">&nbsp;</td>
</tr>
<tr class="settings-level-2">
<th scope="row">
<span>DHCPOFFER:</span>
</th>
<td id="sysinfo-dhcp-offer">&nbsp;</td>
</tr>
<tr class="settings-level-2">
<th scope="row">
<span>DHCPREQUEST:</span>
</th>
<td id="sysinfo-dhcp-request">&nbsp;</td>
</tr>
<tr class="settings-level-2">
<th scope="row">
<span>DHCPACK:</span>
</th>
<td id="sysinfo-dhcp-ack">&nbsp;</td>
</tr>
<tr class="settings-level-2">
<th scope="row">
<span>DHCPNAK:</span>
</th>
<td id="sysinfo-dhcp-nak">&nbsp;</td>
</tr>
<tr class="settings-level-2">
<th scope="row">
<span>DHCPDECLINE:</span>
</th>
<td id="sysinfo-dhcp-decline">&nbsp;</td>
</tr>
<tr class="settings-level-2">
<th scope="row">
<span>DHCPINFORM:</span>
</th>
<td id="sysinfo-dhcp-inform">&nbsp;</td>
</tr>
<tr class="settings-level-2">
<th scope="row">
<span>DHCPRELEASE:</span>
</th>
<td id="sysinfo-dhcp-release">&nbsp;</td>
</tr>
<tr class="settings-level-2">
<th scope="row">
<span>DHCPNOANSWER:</span>
</th>
<td id="sysinfo-dhcp-noanswer">&nbsp;</td>
</tr>
<tr class="settings-level-2">
<th scope="row">
<span>BOOTP:</span>
</th>
<td id="sysinfo-dhcp-bootp">&nbsp;</td>
</tr>
<tr class="settings-level-2">
<th scope="row">
<span>PXE:</span>
</th>
<td id="sysinfo-dhcp-pxe">&nbsp;</td>
</tr>
<tr class="settings-level-2">
<th scope="row">
<span>Allocated / pruned IPv4 leases:</span>
</th>
<td><span id="sysinfo-dhcp-leases-allocated_4">&nbsp;</span> /
<span id="sysinfo-dhcp-leases-pruned_4">&nbsp;</span>
</td>
</tr>
<tr class="settings-level-2">
<th scope="row">
<span>Allocated / pruned IPv6 leases:</span>
</th>
<td><span id="sysinfo-dhcp-leases-allocated_6">&nbsp;</span> /
<span id="sysinfo-dhcp-leases-pruned_6">&nbsp;</span>
</td>
</tr>
</tbody>
</table>
@@ -272,7 +371,7 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array('sysadmin', 'dns', 'dhcp
</div>
</div>
</div>
<div class="overlay" id="sysinfo-dns-overlay">
<div class="overlay" id="sysinfo-metrics-overlay">
<i class="fa fa-sync fa-spin"></i>
</div>
</div>
@@ -311,32 +410,6 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array('sysadmin', 'dns', 'dhcp
<button type="button" class="btn btn-danger confirm-reboot btn-block">Restart system</button>
</div>
</div>
<form role="form" method="post" id="flushlogsform">
<input type="hidden" name="field" value="flushlogs">
<input type="hidden" name="token" value="<?php echo $token; ?>">
</form>
<form role="form" method="post" id="flusharpform">
<input type="hidden" name="field" value="flusharp">
<input type="hidden" name="token" value="<?php echo $token; ?>">
</form>
<form role="form" method="post" id="disablelogsform-noflush">
<input type="hidden" name="field" value="Logging">
<input type="hidden" name="action" value="Disable-noflush">
<input type="hidden" name="token" value="<?php echo $token; ?>">
</form>
<form role="form" method="post" id="poweroffform">
<input type="hidden" name="field" value="poweroff">
<input type="hidden" name="token" value="<?php echo $token; ?>">
</form>
<form role="form" method="post" id="rebootform">
<input type="hidden" name="field" value="reboot">
<input type="hidden" name="token" value="<?php echo $token; ?>">
</form>
<form role="form" method="post" id="restartdnsform">
<input type="hidden" name="field" value="restartdns">
<input type="hidden" name="token" value="<?php echo $token; ?>">
</form>
</div>
</div>
</div>