2021-04-02 18:41:02 +02:00
|
|
|
import chart from 'chart.js'
|
2021-03-05 18:37:43 +01:00
|
|
|
|
|
|
|
let graphIndexCounter = 0;
|
|
|
|
let graphElements = document.querySelectorAll("jl-ntp-graph");
|
2021-03-24 22:18:55 +01:00
|
|
|
|
2021-03-05 18:37:43 +01:00
|
|
|
graphElements.forEach((elememt) => {
|
2021-03-24 22:18:55 +01:00
|
|
|
let ip = elememt.getAttribute("data-server-ip");
|
2021-03-05 18:37:43 +01:00
|
|
|
|
|
|
|
elememt.innerHTML = `
|
2021-03-05 19:07:35 +01:00
|
|
|
<span id="${graphIndexCounter}-Banner" data-index="${graphIndexCounter}" class="ntpBanner">${ip}</span>
|
|
|
|
<span id="${graphIndexCounter}-Content" class="ntpContent">
|
2021-03-05 22:19:21 +01:00
|
|
|
<a target="_blank" href="https://www.ntppool.org/scores/${ip}" class="linkToNtpPool">Server auf dem NTP Pool anzeigen</a>
|
2021-04-02 18:41:02 +02:00
|
|
|
<canvas id="${graphIndexCounter}-Delay"></canvas>
|
|
|
|
<canvas id="${graphIndexCounter}-Score"></canvas>
|
2021-03-05 19:07:35 +01:00
|
|
|
</span>
|
2021-03-05 18:37:43 +01:00
|
|
|
`;
|
|
|
|
let currentIndex = graphIndexCounter;
|
|
|
|
graphIndexCounter++;
|
|
|
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
xhr.onreadystatechange = function (){
|
2021-04-02 18:41:02 +02:00
|
|
|
if(xhr.status === 200 && xhr.readyState === 4){
|
2021-03-24 22:18:55 +01:00
|
|
|
let rawData = JSON.parse(this.responseText);
|
|
|
|
let x = [];
|
|
|
|
let yScore = [];
|
|
|
|
let yDelay = [];
|
2021-04-02 18:41:02 +02:00
|
|
|
rawData["history"].forEach((entry, index) => {
|
|
|
|
let date = new Date(entry["ts"] * 1000).toLocaleDateString();
|
|
|
|
if(index % 10 !== 0){
|
|
|
|
date = "";
|
|
|
|
}
|
|
|
|
x.push(date);
|
2021-03-05 18:37:43 +01:00
|
|
|
yScore.push(entry["score"]);
|
|
|
|
yDelay.push(entry["offset"]);
|
|
|
|
});
|
|
|
|
|
2021-04-02 18:41:02 +02:00
|
|
|
drawPlot(currentIndex + "-Delay", x, yDelay, "Delay");
|
|
|
|
drawPlot(currentIndex + "-Score", x, yScore, "Score");
|
2021-03-05 18:37:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xhr.open("GET", "https://www.ntppool.org/scores/" + ip + "/json?monitor=*&limit=400");
|
|
|
|
xhr.send();
|
|
|
|
});
|
|
|
|
|
2021-03-24 22:18:55 +01:00
|
|
|
function drawPlot(elementName, x, y, title){
|
2021-04-02 18:41:02 +02:00
|
|
|
let ctx = document.getElementById(elementName).getContext('2d');
|
2021-03-05 20:25:17 +01:00
|
|
|
|
2021-04-02 18:41:02 +02:00
|
|
|
new Chart(ctx, {
|
|
|
|
type: 'line',
|
|
|
|
responsive: true,
|
|
|
|
scaleShowVerticalLines: false,
|
|
|
|
showTooltips: false,
|
|
|
|
data: {
|
|
|
|
labels: x,
|
|
|
|
datasets: [{
|
|
|
|
label: title,
|
|
|
|
data: y,
|
|
|
|
borderColor: '#199a87',
|
|
|
|
fill: false,
|
|
|
|
radius: 0,
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
});
|
2021-03-05 18:37:43 +01:00
|
|
|
}
|