This commit is contained in:
杜恒
2021-05-20 09:27:35 +08:00
parent 30d997bcca
commit 088c1b5400
16 changed files with 361 additions and 24 deletions

View File

@@ -1,3 +1,209 @@
document.addEventListener('DOMContentLoaded', () => {
console.log(1);
})
/* 转换字节 */
const bytesToSize = bytes => {
const k = 1024,
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
};
const categories = [];
const upSeries = [];
const downSeries = [];
const flowDom = document.querySelector('#flow');
const workDom = document.querySelector('#work');
const flowChart = flowDom && echarts.init(flowDom);
const workChart = workDom && echarts.init(workDom);
if (flowDom && workDom) initChart();
function initChart() {
$.ajax({
url: Joe.BASE_API,
type: 'POST',
dataType: 'json',
data: {
routeType: 'server_status'
},
success(res) {
{
$('.joe_census__server-item .count .up').html(`总发送:${bytesToSize(res.upTotal)}`);
$('.joe_census__server-item .count .down').html(`总接收:${bytesToSize(res.downTotal)}`);
const stamp = new Date();
const hours = String(stamp.getHours()).padStart(2, 0);
const minutes = String(stamp.getMinutes()).padStart(2, 0);
const seconds = String(stamp.getSeconds()).padStart(2, 0);
const time = `${hours}:${minutes}:${seconds}`;
categories.push(time);
upSeries.push(res.up);
downSeries.push(res.down);
if (categories.length > 5) categories.shift();
if (upSeries.length > 5) upSeries.shift();
if (downSeries.length > 5) downSeries.shift();
flowChart.setOption({
title: {
subtext: '单位 KB/s'
},
grid: {
left: '3%',
right: '4%',
bottom: '0',
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985'
}
}
},
xAxis: {
axisTick: {
show: false
},
type: 'category',
boundaryGap: false,
data: categories
},
yAxis: {
type: 'value'
},
series: [
{
type: 'line',
name: '上行',
smooth: true,
showSymbol: false,
itemStyle: {
normal: {
color: '#f39494',
areaStyle: {
color: '#f39494'
},
lineStyle: {
width: 2,
color: '#f39494'
}
}
},
stack: '总量',
data: upSeries
},
{
type: 'line',
name: '下行',
smooth: true,
showSymbol: false,
itemStyle: {
normal: {
color: '#9dd3e8',
areaStyle: {
color: '#9dd3e8'
},
lineStyle: {
width: 2,
color: '#9dd3e8'
}
}
},
stack: '总量',
data: downSeries
}
]
});
}
{
/* CPU占用 */
const cpuUse = res.cpu[0];
/* 内存占用 */
const memoryRealUse = Math.round((res.memory.memRealUsed / res.memory.memTotal) * 1000) / 10;
/* 内存缓冲 */
const memoryCacheUse = Math.round((res.memory.memCached / res.memory.memTotal) * 1000) / 10;
/* 系统缓冲 */
const memoryBufferUse = Math.round((res.memory.memBuffers / res.memory.memTotal) * 1000) / 10;
/* 系统负载 */
const systemLoad = Math.round((res.load.one / res.load.max) * 100) > 100 ? 100 : Math.round((res.load.one / res.load.max) * 100);
workChart.setOption({
title: {
subtext: '单位 百分比'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
left: '3%',
right: '3%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
axisTick: {
show: false
},
data: ['CPU占用', '内存占用', '系统缓冲', '内存缓冲', '系统负载']
},
yAxis: {
type: 'value'
},
series: {
data: [
{
name: 'CPU占用',
value: cpuUse,
itemStyle: {
color: '#b3c25a'
}
},
{
name: '内存占用',
value: memoryRealUse,
itemStyle: {
color: '#67b580'
}
},
{
name: '系统缓冲',
value: memoryBufferUse,
itemStyle: {
color: '#86ba71'
}
},
{
name: '内存缓冲',
value: memoryCacheUse,
itemStyle: {
color: '#feb041'
}
},
{
name: '系统负载',
value: systemLoad,
itemStyle: {
color: '#fd7e55'
}
}
],
type: 'bar',
showBackground: true,
label: {
show: true,
color: '#ffffff',
formatter: params => `${params.data.value} %`
},
backgroundStyle: {
color: 'rgba(180, 180, 180, 0.2)'
}
}
});
}
setTimeout(initChart, 2000);
}
});
}
});

View File

@@ -1 +1 @@
document.addEventListener("DOMContentLoaded",()=>{console.log(1)});
document.addEventListener("DOMContentLoaded",()=>{function e(){$.ajax({url:Joe.BASE_API,type:"POST",dataType:"json",data:{routeType:"server_status"},success(l){{$(".joe_census__server-item .count .up").html(`总发送:${t(l.upTotal)}`),$(".joe_census__server-item .count .down").html(`总接收:${t(l.downTotal)}`);const e=new Date,n=String(e.getHours()).padStart(2,0),i=String(e.getMinutes()).padStart(2,0),m=String(e.getSeconds()).padStart(2,0),d=`${n}:${i}:${m}`;o.push(d),a.push(l.up),r.push(l.down),o.length>5&&o.shift(),a.length>5&&a.shift(),r.length>5&&r.shift(),s.setOption({title:{subtext:"单位 KB/s"},grid:{left:"3%",right:"4%",bottom:"0",containLabel:!0},tooltip:{trigger:"axis",axisPointer:{type:"cross",label:{backgroundColor:"#6a7985"}}},xAxis:{axisTick:{show:!1},type:"category",boundaryGap:!1,data:o},yAxis:{type:"value"},series:[{type:"line",name:"上行",smooth:!0,showSymbol:!1,itemStyle:{normal:{color:"#f39494",areaStyle:{color:"#f39494"},lineStyle:{width:2,color:"#f39494"}}},stack:"总量",data:a},{type:"line",name:"下行",smooth:!0,showSymbol:!1,itemStyle:{normal:{color:"#9dd3e8",areaStyle:{color:"#9dd3e8"},lineStyle:{width:2,color:"#9dd3e8"}}},stack:"总量",data:r}]})}{const e=l.cpu[0],t=Math.round(l.memory.memRealUsed/l.memory.memTotal*1e3)/10,o=Math.round(l.memory.memCached/l.memory.memTotal*1e3)/10,a=Math.round(l.memory.memBuffers/l.memory.memTotal*1e3)/10,r=Math.round(l.load.one/l.load.max*100)>100?100:Math.round(l.load.one/l.load.max*100);i.setOption({title:{subtext:"单位 百分比"},tooltip:{trigger:"axis",axisPointer:{type:"shadow"}},grid:{left:"3%",right:"3%",bottom:"3%",containLabel:!0},xAxis:{type:"category",axisTick:{show:!1},data:["CPU占用","内存占用","系统缓冲","内存缓冲","系统负载"]},yAxis:{type:"value"},series:{data:[{name:"CPU占用",value:e,itemStyle:{color:"#b3c25a"}},{name:"内存占用",value:t,itemStyle:{color:"#67b580"}},{name:"系统缓冲",value:a,itemStyle:{color:"#86ba71"}},{name:"内存缓冲",value:o,itemStyle:{color:"#feb041"}},{name:"系统负载",value:r,itemStyle:{color:"#fd7e55"}}],type:"bar",showBackground:!0,label:{show:!0,color:"#ffffff",formatter:e=>`${e.data.value} %`},backgroundStyle:{color:"rgba(180, 180, 180, 0.2)"}}})}setTimeout(e,2e3)}})}const t=e=>{const t=1024,o=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],a=Math.floor(Math.log(e)/Math.log(t));return(e/Math.pow(t,a)).toPrecision(3)+" "+o[a]},o=[],a=[],r=[],l=document.querySelector("#flow"),n=document.querySelector("#work"),s=l&&echarts.init(l),i=n&&echarts.init(n);l&&n&&e()});

View File

@@ -327,6 +327,7 @@ document.addEventListener('DOMContentLoaded', () => {
const type = $('.joe_comment__respond-form').attr('data-type');
const parent = $('.joe_comment__respond-form').attr('data-coid');
const author = $(".joe_comment__respond-form .head input[name='author']").val();
const _ = $(".joe_comment__respond-form input[name='_']").val();
const mail = $(".joe_comment__respond-form .head input[name='mail']").val();
let text = $(".joe_comment__respond-form .body textarea[name='text']").val();
if (author.trim() === '') return Qmsg.info('请输入昵称!');
@@ -346,7 +347,7 @@ document.addEventListener('DOMContentLoaded', () => {
$.ajax({
url,
type: 'POST',
data: { author, mail, text, parent, captcha },
data: { author, mail, text, parent, captcha, _ },
dataType: 'text',
success(res) {
let arr = [],
@@ -364,9 +365,9 @@ document.addEventListener('DOMContentLoaded', () => {
}
},
error() {
isSubmit = false
isSubmit = false;
$('.joe_comment__respond-form .foot .submit button').html('发表评论');
Qmsg.warning('发送失败!请刷新重试!')
Qmsg.warning('发送失败!请刷新重试!');
}
});
});

File diff suppressed because one or more lines are too long