1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-02 23:23:28 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

调整系统后台服务器状态检测接口,网站状态检测功能完成

This commit is contained in:
2022-03-15 01:42:48 +08:00
parent 186f5664e0
commit 39c56e36d4
5 changed files with 62 additions and 20 deletions

View File

@@ -21,11 +21,14 @@ function startCheck() {
$(".info-ok").removeClass("info-ok");
$(".info-err").removeClass("info-err");
var i = 0, timeSpan = 300;
setTimeout(checkOnlineStatus, timeSpan * ++i);
setTimeout(checkBackendStatus, timeSpan * ++i);
setTimeout(checkTimeOff, timeSpan * ++i);
setTimeout(finishCheck, timeSpan * ++i);
//执行前等待一段时间,显得更加真实
// 给定一个阶梯值,每次增加一个阶梯值同时加上一个随机数
var i = 0, timeSpan = 80;
setTimeout(checkOnlineStatus, timeSpan * ++i + Math.random() * 600);
setTimeout(checkBackendStatus, timeSpan * ++i + Math.random() * 600);
setTimeout(checkFrontendStatus, timeSpan * ++i + Math.random() * 600);
setTimeout(checkTimeOff, timeSpan * ++i + Math.random() * 600);
setTimeout(finishCheck, timeSpan * ++i + Math.random() * 600);
}
function checkOnlineStatus() {
@@ -36,21 +39,42 @@ function checkOnlineStatus() {
function checkBackendStatus() {
var backendStatus = false;
getRequest("/status/getProcessCpu", {})
getRequest("/status/get", {})
.then(function (response) {
console.log("response.data", response.data);
if (response.data == 0) {
backendStatus = true;
if (response.data.server === "OK") {
$("#backendStatus").text("后台连接正常");
$("#backendStatus").addClass("info-ok");
} else {
$("#backendStatus").text("服务器内部异常");
$("#backendStatus").addClass("info-err");
}
$("#backendStatus").text("后台连接正常");
$("#backendStatus").addClass("info-ok");
})
.catch(function (error) {
$("#backendStatus").text("后台连接异常");
$("#backendStatus").text("无法连接到服务器");
$("#backendStatus").addClass("info-err");
});
}
function checkFrontendStatus() {
var backendStatus = false;
getRequest("../get-frontend-status", {})
.then(function (response) {
console.log("response.data", response.data);
if (response.data.server === "OK") {
$("#frontendStatus").text("前台连接正常");
$("#frontendStatus").addClass("info-ok");
} else {
$("#frontendStatus").text("服务器内部异常");
$("#frontendStatus").addClass("info-err");
}
})
.catch(function (error) {
$("#frontendStatus").text("无法连接到服务器");
$("#frontendStatus").addClass("info-err");
});
}
function finishCheck() {
document.getElementById("checkBtn").value = "重新检测";
document.getElementById("checkBtn").disabled = "";
@@ -80,7 +104,7 @@ function checkTimeOff(targetUrl = null) {
if (xhr.readyState === 2) {
// 获取响应头里的时间戳
time = xhr.getResponseHeader("Date");
console.log("请求结束时本地时间(东八区时间): " + new Date(time).getTime());
// console.log("请求结束时本地时间(东八区时间): " + new Date(time).getTime());
// requestEndTime = Date.now();
// console.log("请求开始时本地时间(用于计算时间差): " + requestStartTime);
@@ -93,8 +117,11 @@ function checkTimeOff(targetUrl = null) {
var target = document.getElementById("timeOff");
if (target) {
target.innerHTML = "本地时间比服务器" + (timeOff > 0 ? "慢" : "快") + Math.abs(timeOff / 1000) + "秒";
$(target).addClass("info-ok");
// 产生随机时间(测试功能用)
// timeOff = Math.random() * 10 * 60 * 1000;
var spanSeconds = Math.abs(timeOff / 1000);
target.innerHTML = "本地时间比服务器" + (timeOff > 0 ? "慢" : "快") + spanSeconds.toFixed(3) + "秒";
$(target).addClass((spanSeconds >= 5 * 60) ? "info-err" : "info-ok");
}
}
};

View File

@@ -38,4 +38,8 @@ router.get('/status', function (req, res) {
});
});
router.get('/get-frontend-status', function (req, res) {
res.end(JSON.stringify({ "server": "OK" }));
});
module.exports = router;

View File

@@ -16,7 +16,7 @@
// refer: https://www.cnblogs.com/yzeng/p/8268731.html
function getPageText() {
var str = document.documentElement.innerText;
str += "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 数字和英文全部包含进去
str += "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 数字和英文全部包含进去,避免因为部分数字或字母造成大量生成字体
var res = [].filter.call(str, (s, i, o) => o.indexOf(s) == i).sort().join('').trim();
return res;
}

View File

@@ -37,7 +37,8 @@
</div>
<div>
<h3 class="title">网络后台状态</h3>
<span id="backendStatus" class="info"></span>
后台服务器:<span id="backendStatus" class="info"></span><br>
前台服务器:<span id="frontendStatus" class="info"></span>
</div>
<div>
<h3 class="title">网络数据库状态</h3>

View File

@@ -30,14 +30,24 @@ public class StatusController {
// return processCpu;
// }
@ApiOperation(value = "系统负载", notes = "获取服务器当前系统负载。")
@RequestMapping(value = "getSystemLoadAverage", method = {RequestMethod.GET})
@ApiOperation(value = "系统状态", notes = "获取服务器当前系统负载。SystemLoadAverage返回-1时代表不支持。")
@RequestMapping(value = "get", method = {RequestMethod.GET})
@ResponseBody
public Object getSystemLoadAverage() {
public Object get() {
OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
return operatingSystemMXBean.getSystemLoadAverage();
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("server", "OK");
return hashMap;
}
// @ApiOperation(value = "系统负载", notes = "获取服务器当前系统负载。SystemLoadAverage返回-1时代表不支持。")
// @RequestMapping(value = "get", method = {RequestMethod.GET})
// @ResponseBody
// public Object get() {
// OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
// return operatingSystemMXBean.getSystemLoadAverage();
// }
// @ApiOperation(value = "服务端状态", notes = "获取服务器当前状态信息")
// @RequestMapping(value = "get", method = {RequestMethod.GET})
// @ResponseBody