elstat/static/index.html

73 lines
1.8 KiB
HTML

<html>
<head>
<style>
p {
font-size: 15pt;
}
</style>
<script>
// https://stackoverflow.com/a/4033310
function httpGetAsync(theUrl, callback)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
function genText(data) {
base = `${data.description} - status: ${data.status}`;
if('latency' in data) {
base += ` - latency: ${data.latency} ms`;
}
return base;
}
function curStatHandler(text) {
let payload = JSON.parse(text);
for(const service in payload) {
let data = payload[service];
let elementId = `${service}-description`;
let existingElement = document.getElementById(elementId);
if (existingElement === null) {
let element = document.createElement('p');
element.id = elementId;
element.innerText = genText(data);
document.body.appendChild(element);
} else {
existingElement.innerText = genText(data);
}
}
}
function fetchStatus () {
httpGetAsync("http://127.0.0.1:8069/api/current_status", curStatHandler);
}
window.onload = function () {
fetchStatus();
setInterval(() => {
fetchStatus();
}, 3000)
}
</script>
</head>
<body>
</body>
</html>