Skip to content

Instantly share code, notes, and snippets.

@dkuku
Created August 6, 2019 15:17
Show Gist options
  • Save dkuku/3069cade9aa55796a7ada9144d60c80f to your computer and use it in GitHub Desktop.
Save dkuku/3069cade9aa55796a7ada9144d60c80f to your computer and use it in GitHub Desktop.
simple server status monitoring page
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1 class="">Server status page</h1>
</body>
</html>
<script>
const services = [
"authn",
"logger",
"queue",
"search",
]
var body = document.getElementsByTagName('body')[0]
services.map(service=>{
var para = document.createElement("div");
para.classList.add(service);
var node = document.createTextNode(service);
para.appendChild(node);
body.appendChild(para);
})
function pollFunc(fn, timeout, interval) {
var startTime = (new Date()).getTime();
interval = interval || 1000,
canPoll = true;
(function p() {
canPoll = ((new Date).getTime() - startTime ) <= timeout;
if (!fn() && canPoll) { // ensures the function exucutes
setTimeout(p, interval);
}
})();
}
pollFunc(sendHeartBeat, 60000, 5000);
function sendHeartBeat(params) {
services.map(service=>{
var x = document.getElementsByClassName(service)
fetch(`http://website/${servicce}`)
.then(function(response) {
return response
}).then(function (response){
if(response.status == 200 || response.status == 401) {
x[0].style.backgroundColor = "green"
} else {
console.log(response.statusText)
x[0].style.backgroundColor = "red"
}
}).catch(function (e){
x[0].style.backgroundColor = "red"
console.log(e)
});
})
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment