|
|
@ -22,6 +22,7 @@ async function deleteHost(hostId) { |
|
|
|
async function fetchHosts() { |
|
|
|
var tbody = $("#tblHosts > tbody"); |
|
|
|
tbody.empty(); |
|
|
|
hosts = []; |
|
|
|
var res = await $.getJSON("/api/host"); |
|
|
|
console.log("Got hosts: ", res); |
|
|
|
for (let host of res) { |
|
|
@ -33,7 +34,8 @@ async function fetchHosts() { |
|
|
|
deleteHost(host.hostId); |
|
|
|
}).appendTo(row); |
|
|
|
} |
|
|
|
updateGraphs(res); |
|
|
|
hosts = res; |
|
|
|
updateGraphs(); |
|
|
|
} |
|
|
|
|
|
|
|
async function fetchPings(hostId, start, end) { |
|
|
@ -54,13 +56,17 @@ async function transformChartData(pings) { |
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
async function updateGraphs(hosts) { |
|
|
|
var charts = $("#charts"); |
|
|
|
async function updateGraphs() { |
|
|
|
var chartDiv = $("#charts"); |
|
|
|
chartDiv.empty(); |
|
|
|
charts = []; |
|
|
|
var pastMinutes = $("#inpHistoryPast").val(); |
|
|
|
var start = Date.now() - pastMinutes * 60 * 1000; |
|
|
|
var end = Date.now(); |
|
|
|
for (let host of hosts) { |
|
|
|
console.log("Appending ", host); |
|
|
|
var before = Date.now() - 300000; |
|
|
|
var val = await transformChartData(await fetchPings(host.hostId, before, Date.now())); |
|
|
|
$("<canvas>", { id: "chart_" + host.hostId, width: 200, height: 200 }).appendTo(charts); |
|
|
|
var val = await transformChartData(await fetchPings(host.hostId, start, end)); |
|
|
|
$("<canvas>", { id: "chart_" + host.hostId, width: 200, height: 200 }).appendTo(chartDiv); |
|
|
|
var ctx = document.getElementById('chart_' + host.hostId).getContext('2d'); |
|
|
|
charts[host.hostId] = new Chart(ctx, { |
|
|
|
type: 'line', |
|
|
@ -132,6 +138,11 @@ $('#btnDebug').click(async () => { |
|
|
|
console.log("DEBUG"); |
|
|
|
}); |
|
|
|
|
|
|
|
$("#frmHistory").submit((event) => { |
|
|
|
event.preventDefault(); |
|
|
|
updateGraphs(); |
|
|
|
}); |
|
|
|
|
|
|
|
$("#frmHostAdd").submit((event) => { |
|
|
|
event.preventDefault(); |
|
|
|
var name = $("#inpNameAdd").val(); |
|
|
|