2020-12-09 06:05:40 -05:00
|
|
|
|
{{define "theme-default/home"}}
|
2019-12-08 03:59:58 -05:00
|
|
|
|
{{template "common/header" .}}
|
2020-12-18 21:57:10 -05:00
|
|
|
|
{{if ts .CustomCSS}}
|
2020-12-18 23:43:03 -05:00
|
|
|
|
{{tag "style"}}
|
2020-12-18 21:57:10 -05:00
|
|
|
|
{{.CustomCSS|css}}
|
2020-12-18 23:43:03 -05:00
|
|
|
|
{{tag "/style"}}
|
2020-12-18 21:57:10 -05:00
|
|
|
|
{{end}}
|
2019-12-08 03:59:58 -05:00
|
|
|
|
{{template "common/menu" .}}
|
|
|
|
|
<div class="nb-container">
|
|
|
|
|
<div class="ui container">
|
2019-12-11 03:20:33 -05:00
|
|
|
|
<div class="ui four stackable status cards">
|
2019-12-10 04:57:57 -05:00
|
|
|
|
<div v-for='server in servers' :id="server.ID" class="card">
|
2020-12-18 23:43:03 -05:00
|
|
|
|
<div class="content" v-if='server.Host'>
|
2020-03-22 09:43:37 -04:00
|
|
|
|
<div class="header"><i :class="server.Host.CountryCode + ' flag'"></i><i
|
|
|
|
|
v-if='server.Host.Platform == "darwin"' class="apple icon"></i><i
|
|
|
|
|
v-if='server.Host.Platform == "linux"' class="linux icon"></i><i
|
2019-12-10 05:11:15 -05:00
|
|
|
|
v-if='server.Host.Platform == "windows"' class="windows icon"></i><i
|
2020-12-18 23:43:03 -05:00
|
|
|
|
v-if='server.Host.Platform == "freebsd"' class="freebsd icon"></i>@#server.Name + (server.live?'':' [已离线]')#@
|
2019-12-10 02:33:05 -05:00
|
|
|
|
<i class="yellow info circle icon"></i>
|
|
|
|
|
<div class='ui content popup'>
|
2019-12-10 02:49:06 -05:00
|
|
|
|
系统:@#server.Host.Platform#@-@#server.Host.PlatformVersion#@ [<span
|
|
|
|
|
v-if='server.Host.Virtualization'>@#server.Host.Virtualization#@:</span>@#server.Host.Arch#@]<br>
|
|
|
|
|
CPU:@#server.Host.CPU#@<br>
|
2019-12-11 08:50:49 -05:00
|
|
|
|
硬盘:@#formatByteSize(server.State.DiskUsed)#@/@#formatByteSize(server.Host.DiskTotal)#@<br>
|
|
|
|
|
内存:@#formatByteSize(server.State.MemUsed)#@/@#formatByteSize(server.Host.MemTotal)#@<br>
|
|
|
|
|
交换:@#formatByteSize(server.State.SwapUsed)#@/@#formatByteSize(server.Host.SwapTotal)#@<br>
|
2019-12-10 04:57:57 -05:00
|
|
|
|
流量:<i
|
2019-12-11 01:10:48 -05:00
|
|
|
|
class='arrow alternate circle down outline icon'></i>@#formatByteSize(server.State.NetInTransfer)#@<i
|
2019-12-10 04:57:57 -05:00
|
|
|
|
class='arrow alternate circle up outline icon'></i>@#formatByteSize(server.State.NetOutTransfer)#@<br>
|
|
|
|
|
启动:@# formatTimestamp(server.Host.BootTime) #@<br>
|
2020-11-06 07:56:46 -05:00
|
|
|
|
版本:@#server.Host.Version#@<br>
|
2019-12-10 02:33:05 -05:00
|
|
|
|
</div>
|
2019-12-09 03:02:49 -05:00
|
|
|
|
</div>
|
2019-12-08 10:18:29 -05:00
|
|
|
|
<div class="description">
|
2019-12-09 03:02:49 -05:00
|
|
|
|
<div class="ui grid">
|
|
|
|
|
<div class="three wide column">CPU</div>
|
|
|
|
|
<div class="thirteen wide column">
|
2020-12-18 23:43:03 -05:00
|
|
|
|
<div :class="formatPercent(server.live,server.State.CPU, 100).class">
|
|
|
|
|
<div class="bar" :style="formatPercent(server.live,server.State.CPU, 100).style">
|
2019-12-09 03:02:49 -05:00
|
|
|
|
<div class="progress"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2019-12-09 10:45:23 -05:00
|
|
|
|
<div class="three wide column">内存</div>
|
2019-12-09 03:02:49 -05:00
|
|
|
|
<div class="thirteen wide column">
|
2020-12-18 23:43:03 -05:00
|
|
|
|
<div :class="formatPercent(server.live,server.State.MemUsed, server.Host.MemTotal).class">
|
|
|
|
|
<div class="bar"
|
|
|
|
|
:style="formatPercent(server.live,server.State.MemUsed, server.Host.MemTotal).style">
|
2019-12-09 03:02:49 -05:00
|
|
|
|
<div class="progress"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2019-12-09 10:45:23 -05:00
|
|
|
|
<div class="three wide column">交换</div>
|
2019-12-09 03:02:49 -05:00
|
|
|
|
<div class="thirteen wide column">
|
2020-12-18 23:43:03 -05:00
|
|
|
|
<div :class="formatPercent(server.live,server.State.SwapUsed, server.Host.SwapTotal).class">
|
|
|
|
|
<div class="bar"
|
|
|
|
|
:style="formatPercent(server.live,server.State.SwapUsed, server.Host.SwapTotal).style">
|
2019-12-09 03:02:49 -05:00
|
|
|
|
<div class="progress"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2019-12-08 10:18:29 -05:00
|
|
|
|
</div>
|
2019-12-09 05:14:31 -05:00
|
|
|
|
<div class="three wide column">网络</div>
|
|
|
|
|
<div class="thirteen wide column">
|
2019-12-10 02:33:05 -05:00
|
|
|
|
<i class="arrow alternate circle down outline icon"></i>
|
2019-12-10 04:57:57 -05:00
|
|
|
|
@#formatByteSize(server.State.NetInSpeed)#@/s
|
2019-12-10 02:33:05 -05:00
|
|
|
|
<i class="arrow alternate circle up outline icon"></i>
|
2019-12-10 04:57:57 -05:00
|
|
|
|
@#formatByteSize(server.State.NetOutSpeed)#@/s
|
2019-12-09 10:45:23 -05:00
|
|
|
|
</div>
|
|
|
|
|
<div class="three wide column">硬盘</div>
|
|
|
|
|
<div class="thirteen wide column">
|
2020-12-18 23:43:03 -05:00
|
|
|
|
<div :class="formatPercent(server.live,server.State.DiskUsed, server.Host.DiskTotal).class">
|
|
|
|
|
<div class="bar"
|
|
|
|
|
:style="formatPercent(server.live,server.State.DiskUsed, server.Host.DiskTotal).style">
|
2019-12-09 10:45:23 -05:00
|
|
|
|
<div class="progress"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="three wide column">在线</div>
|
|
|
|
|
<div class="thirteen wide column">
|
2019-12-10 04:57:57 -05:00
|
|
|
|
<i class="clock icon"></i>@#secondToDate(server.State.Uptime)#@
|
2019-12-09 05:14:31 -05:00
|
|
|
|
</div>
|
2019-12-08 10:18:29 -05:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2020-10-24 09:29:05 -04:00
|
|
|
|
<div class="content" v-else>
|
2020-03-22 09:43:37 -04:00
|
|
|
|
<p>@#server.Name#@</p>
|
|
|
|
|
<p>节点已离线</p>
|
|
|
|
|
</div>
|
2019-12-08 10:18:29 -05:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2019-12-08 03:59:58 -05:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{{template "common/footer" .}}
|
2019-12-09 05:14:31 -05:00
|
|
|
|
<script>
|
2019-12-10 04:57:57 -05:00
|
|
|
|
const initData = {{.Servers }};
|
2019-12-10 02:33:05 -05:00
|
|
|
|
var statusCards = new Vue({
|
|
|
|
|
el: 'div.status.cards',
|
2019-12-10 02:49:06 -05:00
|
|
|
|
delimiters: ['@#', '#@'],
|
2019-12-10 02:33:05 -05:00
|
|
|
|
data: {
|
2019-12-10 04:57:57 -05:00
|
|
|
|
servers: initData,
|
2020-10-24 09:29:05 -04:00
|
|
|
|
pulled: false,
|
2020-12-18 23:43:03 -05:00
|
|
|
|
cache: [],
|
2019-12-10 02:33:05 -05:00
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
$('.yellow.info.icon').popup({
|
|
|
|
|
popup: '.ui.content.popup'
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2020-12-18 23:43:03 -05:00
|
|
|
|
formatPercent(live, used, total) {
|
|
|
|
|
const percent = live ? (parseInt(used / total * 100) || 0) : -1
|
|
|
|
|
if (!this.cache[percent]) {
|
|
|
|
|
this.cache[percent] = {
|
|
|
|
|
class: {
|
|
|
|
|
ui: true,
|
|
|
|
|
progress: true,
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
'transition-duration': '300ms',
|
|
|
|
|
'min-width': 'unset',
|
|
|
|
|
width: percent + '% !important',
|
|
|
|
|
},
|
|
|
|
|
percent,
|
|
|
|
|
}
|
|
|
|
|
if (percent < 0) {
|
|
|
|
|
this.cache[percent].style['background-color'] = 'slategray'
|
|
|
|
|
this.cache[percent].class.offline = true
|
|
|
|
|
} else if (percent < 51) {
|
|
|
|
|
this.cache[percent].style['background-color'] = 'lime'
|
|
|
|
|
this.cache[percent].class.fine = true
|
|
|
|
|
} else if (percent < 81) {
|
|
|
|
|
this.cache[percent].style['background-color'] = 'orange'
|
|
|
|
|
this.cache[percent].class.warning = true
|
|
|
|
|
} else {
|
|
|
|
|
this.cache[percent].style['background-color'] = 'crimson'
|
|
|
|
|
this.cache[percent].class.error = true
|
|
|
|
|
}
|
2020-10-24 09:29:05 -04:00
|
|
|
|
}
|
2020-12-18 23:43:03 -05:00
|
|
|
|
return this.cache[percent]
|
2020-10-24 09:29:05 -04:00
|
|
|
|
},
|
2019-12-10 04:57:57 -05:00
|
|
|
|
secondToDate(s) {
|
|
|
|
|
var d = Math.floor(s / 3600 / 24);
|
2019-12-11 05:03:49 -05:00
|
|
|
|
var h = Math.floor(s / 3600 % 24);
|
2019-12-10 04:57:57 -05:00
|
|
|
|
var m = Math.floor((s / 60 % 60));
|
|
|
|
|
var s = Math.floor((s % 60));
|
|
|
|
|
return result = d + "天" + h + "小时" + m + "分钟" + s + "秒";
|
|
|
|
|
},
|
|
|
|
|
formatTimestamp(t) {
|
|
|
|
|
return new Date(t * 1000).toLocaleString()
|
|
|
|
|
},
|
|
|
|
|
formatByteSize(bs) {
|
|
|
|
|
const x = readableBytes(bs)
|
|
|
|
|
return x != "NaN undefined" ? x : '0 KB'
|
|
|
|
|
}
|
2019-12-10 02:33:05 -05:00
|
|
|
|
}
|
2019-12-10 04:57:57 -05:00
|
|
|
|
})
|
2020-10-24 21:57:50 -04:00
|
|
|
|
const wsProtocol = window.location.protocol == "https:" ? "wss" : "ws"
|
2020-10-24 09:29:05 -04:00
|
|
|
|
const ws = new WebSocket(wsProtocol + '://' + window.location.host + '/ws');
|
2019-12-10 04:57:57 -05:00
|
|
|
|
ws.onopen = function (evt) {
|
|
|
|
|
$.suiAlert({
|
|
|
|
|
title: '实时通道建立',
|
|
|
|
|
description: '可以实时获取最新监控数据啦',
|
|
|
|
|
type: 'success',
|
|
|
|
|
time: '2',
|
|
|
|
|
position: 'top-center',
|
|
|
|
|
});
|
|
|
|
|
ws.send('track');
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
ws.send('track');
|
|
|
|
|
console.log('追加监控时间')
|
|
|
|
|
}, 1000 * 60 * 6);
|
|
|
|
|
}
|
|
|
|
|
ws.onmessage = function (evt) {
|
|
|
|
|
const oldServers = statusCards.servers
|
|
|
|
|
statusCards.servers = JSON.parse(evt.data)
|
2020-10-24 09:29:05 -04:00
|
|
|
|
statusCards.pulled++
|
2019-12-10 04:57:57 -05:00
|
|
|
|
const keys = Object.keys(statusCards.servers)
|
|
|
|
|
for (let i = 0; i < keys.length; i++) {
|
|
|
|
|
const ns = statusCards.servers[keys[i]];
|
2020-12-18 23:43:03 -05:00
|
|
|
|
if (!ns.Host) ns.live = false
|
|
|
|
|
else {
|
|
|
|
|
const lastActive = new Date(ns.LastActive).getTime()
|
|
|
|
|
if (statusCards.pulled > 3 && Date.now() - lastActive > 5 * 1000) {
|
|
|
|
|
ns.live = false
|
|
|
|
|
} else {
|
|
|
|
|
ns.live = true
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-10 04:57:57 -05:00
|
|
|
|
for (let j = 0; j < oldServers.length; j++) {
|
|
|
|
|
const os = oldServers[j];
|
|
|
|
|
if (ns.ID == os.ID) {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
// 新加入的仔
|
|
|
|
|
$('#' + ns.ID + ' .yellow.info.icon').popup({
|
|
|
|
|
popup: '.ui.content.popup'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ws.onclose = function () {
|
|
|
|
|
$.suiAlert({
|
|
|
|
|
title: '实时通道断开',
|
|
|
|
|
description: '无法实时获取最新监控数据咯',
|
|
|
|
|
type: 'warning',
|
|
|
|
|
time: '2',
|
|
|
|
|
position: 'top-center',
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-12-09 05:14:31 -05:00
|
|
|
|
</script>
|
2019-12-08 03:59:58 -05:00
|
|
|
|
{{end}}
|