You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
TS-Website/js/status.js

63 lines
2.9 KiB

9 years ago
$(document).ready(function () {
checkStatus();
var intervalid = setInterval(function () {
checkStatus();
}, 10 * 1000);
});
9 years ago
function checkStatus() {
9 years ago
$.ajax({
url: apiurl,
9 years ago
success: function (json) {
json = json.tsstatus;
9 years ago
var result = "";
if (json.success) {
var clientsonline = json.clientsonline;
var maxclients = json.maxclients;
var clientsprecent = Math.round(json.clientsonline * 100 / json.maxclients);
var version = json.version;
var platform = json.platform;
var uptime = json.uptime;
var averagePacketloss = Math.round(json.averagePacketloss * 10000) / 100;
9 years ago
var averagePing = Math.round(json.averagePing * 100) / 100;
var platformIcon = '<i class="fa %s fa-fw" title="' + platform + '" aria-hidden="true"></i>';
switch (platform.toLowerCase()) {
case "windows":
platformIcon = platformIcon.replace(/%s/, 'fa-windows');
break;
case "linux":
platformIcon = platformIcon.replace(/%s/, 'fa-linux');
break;
case "os x":
case "macos":
platformIcon = platformIcon.replace(/%s/, 'fa-apple');
break;
default:
platformIcon = platform;
}
9 years ago
result =
'<p><i class="fa fa-power-off fa-fw" aria-hidden="true"></i> ' + statusOnline + ': <span class="label label-success">' + clientsonline + ' / ' + maxclients + ' (' + clientsprecent + '%)</span></p>' +
'<p><i class="fa fa-clock-o fa-fw" aria-hidden="true"></i> ' + statusUptime + ': <span class="label label-success">' + uptime + '</span></p>' +
'<p><i class="fa fa-info-circle fa-fw" aria-hidden="true"></i> ' + statusVersion + ': <span class="label label-success">' + version + ' on ' + platformIcon + '</span></p>' +
'<p><i class="fa fa-signal fa-fw" aria-hidden="true"></i> ' + statusAvgping + ': <span class="label label-success">' + averagePing + ' ms</span></p>' +
'<p><i class="fa fa-bolt fa-fw" aria-hidden="true"></i> ' + statusAvgpl + ': <span class="label label-success">' + averagePacketloss + '%</span></p>';
9 years ago
} else {
result = '<p><i class="fa fa-power-off fa-fw" aria-hidden="true"></i> Online: <span class="label label-danger">' + statusOffline + '</span></p>';
9 years ago
}
$("#serverstatus").html(result);
},
error: function (result) {
$("#serverstatus").html('<p><i class="fa fa-power-off fa-fw" aria-hidden="true"></i> ' + statusOnline + ': <span class="label label-danger">ERROR</span></p>');
9 years ago
}
})
}