mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
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:
@@ -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);
|
||||
|
||||
@@ -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
@@ -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"> </td>
|
||||
<td id="sysinfo-dns-cache-size"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<span title="Number of cache insertions">DNS cache insertions:</span>
|
||||
</th>
|
||||
<td id="sysinfo-cache-inserted"> </td>
|
||||
<td id="sysinfo-dns-cache-inserted"> </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"> </td>
|
||||
<td id="sysinfo-dns-cache-evicted"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
DNS cache expiries:
|
||||
</th>
|
||||
<td id="sysinfo-cache-expired"> </td>
|
||||
<td id="sysinfo-dns-cache-expired"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
Immortal DNS cache entries:
|
||||
</th>
|
||||
<td id="sysinfo-cache-immortal"> </td>
|
||||
<td id="sysinfo-dns-cache-immortal"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
Valid A records in cache:
|
||||
</th>
|
||||
<td id="sysinfo-cache-valid-a"> </td>
|
||||
<td id="sysinfo-dns-cache-content-a"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
Valid AAAA records in cache:
|
||||
</th>
|
||||
<td id="sysinfo-cache-valid-aaaa"> </td>
|
||||
<td id="sysinfo-dns-cache-content-aaaa"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
Valid CNAME records in cache:
|
||||
</th>
|
||||
<td id="sysinfo-cache-valid-cname"> </td>
|
||||
<td id="sysinfo-dns-cache-content-cname"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
Valid SRV records in cache:
|
||||
</th>
|
||||
<td id="sysinfo-cache-valid-srv"> </td>
|
||||
<td id="sysinfo-dns-cache-content-srv"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
Valid DS records in cache:
|
||||
</th>
|
||||
<td id="sysinfo-cache-valid-ds"> </td>
|
||||
<td id="sysinfo-dns-cache-content-ds"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
Valid DNSKEY records in cache:
|
||||
</th>
|
||||
<td id="sysinfo-cache-valid-dnskey"> </td>
|
||||
<td id="sysinfo-dns-cache-content-dnskey"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
Other valid records in cache:
|
||||
</th>
|
||||
<td id="sysinfo-cache-valid-other"> </td>
|
||||
<td id="sysinfo-dns-cache-content-other"> </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"> </td>
|
||||
<td id="sysinfo-dns-replies-local"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
Forwarded queries:
|
||||
</th>
|
||||
<td id="sysinfo-replies-extra-forwarded"> </td>
|
||||
<td id="sysinfo-dns-replies-forwarded"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
Unanswered queries:
|
||||
</th>
|
||||
<td id="sysinfo-replies-extra-unanswered"> </td>
|
||||
<td id="sysinfo-dns-replies-unanswered"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<span>Cache optimizer replies:</span>
|
||||
</th>
|
||||
<td id="sysinfo-replies-optimized"> </td>
|
||||
<td id="sysinfo-dns-replies-optimized"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
<span>Authoritative replies:</span>
|
||||
</th>
|
||||
<td id="sysinfo-replies-auth"> </td>
|
||||
<td id="sysinfo-dns-replies-auth"> </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"> </td>
|
||||
</tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
<span>DHCPOFFER:</span>
|
||||
</th>
|
||||
<td id="sysinfo-dhcp-offer"> </td>
|
||||
</tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
<span>DHCPREQUEST:</span>
|
||||
</th>
|
||||
<td id="sysinfo-dhcp-request"> </td>
|
||||
</tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
<span>DHCPACK:</span>
|
||||
</th>
|
||||
<td id="sysinfo-dhcp-ack"> </td>
|
||||
</tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
<span>DHCPNAK:</span>
|
||||
</th>
|
||||
<td id="sysinfo-dhcp-nak"> </td>
|
||||
</tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
<span>DHCPDECLINE:</span>
|
||||
</th>
|
||||
<td id="sysinfo-dhcp-decline"> </td>
|
||||
</tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
<span>DHCPINFORM:</span>
|
||||
</th>
|
||||
<td id="sysinfo-dhcp-inform"> </td>
|
||||
</tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
<span>DHCPRELEASE:</span>
|
||||
</th>
|
||||
<td id="sysinfo-dhcp-release"> </td>
|
||||
</tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
<span>DHCPNOANSWER:</span>
|
||||
</th>
|
||||
<td id="sysinfo-dhcp-noanswer"> </td>
|
||||
</tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
<span>BOOTP:</span>
|
||||
</th>
|
||||
<td id="sysinfo-dhcp-bootp"> </td>
|
||||
</tr>
|
||||
<tr class="settings-level-2">
|
||||
<th scope="row">
|
||||
<span>PXE:</span>
|
||||
</th>
|
||||
<td id="sysinfo-dhcp-pxe"> </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"> </span> /
|
||||
<span id="sysinfo-dhcp-leases-pruned_4"> </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"> </span> /
|
||||
<span id="sysinfo-dhcp-leases-pruned_6"> </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>
|
||||
|
||||
Reference in New Issue
Block a user