nezha/resource/template/theme-default/home.html

246 lines
10 KiB
HTML
Raw Normal View History

{{define "theme-default/home"}} {{template "common/header" .}} {{if ts
.CustomCode}} {{.CustomCode|safe}} {{end}} {{template "common/menu" .}}
2019-12-08 03:59:58 -05:00
<div class="nb-container">
<div class="ui container">
<div id="app">
<div class="ui styled fluid accordion" v-for="group in groups">
<div class="active title">
2022-03-23 10:04:33 -04:00
<i class="dropdown icon"></i>
2022-04-29 08:49:24 -04:00
@#(group.Tag!==''?group.Tag:'{{tr "Default"}}')#@
</div>
<div class="active content">
<div class="ui four stackable status cards">
<div v-for="server in group.data" :id="server.ID" class="ui card">
2022-03-23 09:07:38 -04:00
<div class="content" v-if="server.Host" style="margin-top: 10px; padding-bottom: 5px">
<div class="header">
2022-03-23 09:07:38 -04:00
<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
v-if='server.Host.Platform == "windows"' class="windows icon"></i><i
2022-03-23 10:04:33 -04:00
v-if='server.Host.Platform == "freebsd"' class="freebsd icon"></i>
2022-04-29 08:49:24 -04:00
@#server.Name + (server.live?'':'[{{tr "Offline"}}]')#@
2021-08-06 06:55:37 -04:00
<i class="nezha-secondary-font info circle icon" style="height: 28px"></i>
<div class="ui content popup" style="margin-bottom: 0">
2022-04-29 08:49:24 -04:00
{{tr "Platform"}}:@#server.Host.Platform#@-@#server.Host.PlatformVersion#@
2022-03-23 09:07:38 -04:00
[<span
v-if="server.Host.Virtualization">@#server.Host.Virtualization#@:</span>@#server.Host.Arch#@]<br />
2022-04-29 08:49:24 -04:00
CPU:@#server.Host.CPU#@<br />
{{tr "DiskUsed"}}:@#formatByteSize(server.State.DiskUsed)#@/@#formatByteSize(server.Host.DiskTotal)#@<br />
{{tr "MemUsed"}}:@#formatByteSize(server.State.MemUsed)#@/@#formatByteSize(server.Host.MemTotal)#@<br />
{{tr "SwapUsed"}}:@#formatByteSize(server.State.SwapUsed)#@/@#formatByteSize(server.Host.SwapTotal)#@<br />
{{tr "NetTransfer"}}:<i
2022-03-23 09:07:38 -04:00
class="arrow alternate circle down outline icon"></i>@#formatByteSize(server.State.NetInTransfer)#@<i
class="arrow alternate circle up outline icon"></i>@#formatByteSize(server.State.NetOutTransfer)#@<br />
2022-04-29 08:49:24 -04:00
{{tr "Load"}}:@# toFixed2(server.State.Load1) #@/@# toFixed2(server.State.Load5) #@/@#
2022-03-23 09:07:38 -04:00
toFixed2(server.State.Load15) #@<br />
2022-04-29 08:49:24 -04:00
{{tr "ProcessCount"}}:@# server.State.ProcessCount #@<br />
{{tr "ConnCount"}}:TCP @# server.State.TcpConnCount #@ / UDP @# server.State.UdpConnCount #@<br />
{{tr "BootTime"}}:@# formatTimestamp(server.Host.BootTime) #@<br />
{{tr "LastActive"}}:@# new Date(server.LastActive).toLocaleString() #@<br />
{{tr "Version"}}:@#server.Host.Version#@<br />
</div>
<div class="ui divider" style="margin-bottom: 5px"></div>
</div>
<div class="description">
<div class="ui grid">
<div class="three wide column">CPU</div>
<div class="thirteen wide column">
2022-03-23 09:07:38 -04:00
<div :class="formatPercent(server.live,server.State.CPU, 100).class">
<div class="bar" :style="formatPercent(server.live,server.State.CPU, 100).style">
<small>@#formatPercent(server.live,server.State.CPU,100).percent#@%</small>
</div>
</div>
</div>
2022-04-29 08:49:24 -04:00
<div class="three wide column">{{tr "MemUsed"}}</div>
<div class="thirteen wide column">
2022-03-23 09:07:38 -04: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">
<small>@#parseInt(server.State?server.State.MemUsed/server.Host.MemTotal*100:0)#@%</small>
2019-12-08 10:18:29 -05:00
</div>
</div>
</div>
2022-04-29 08:49:24 -04:00
<div class="three wide column">{{tr "SwapUsed"}}</div>
<div class="thirteen wide column">
2022-03-23 09:07:38 -04: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">
<small>@#parseInt(server.State?server.State.SwapUsed/server.Host.SwapTotal*100:0)#@%</small>
</div>
</div>
</div>
2022-04-29 08:49:24 -04:00
<div class="three wide column">{{tr "NetSpeed"}}</div>
<div class="thirteen wide column">
<i class="arrow alternate circle down outline icon"></i>
@#formatByteSize(server.State.NetInSpeed)#@/s
<i class="arrow alternate circle up outline icon"></i>
@#formatByteSize(server.State.NetOutSpeed)#@/s
</div>
2022-04-29 08:49:24 -04:00
<div class="three wide column">{{tr "DiskUsed"}}</div>
<div class="thirteen wide column">
2022-03-23 09:07:38 -04: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">
<small>@#parseInt(server.State?server.State.DiskUsed/server.Host.DiskTotal*100:0)#@%</small>
</div>
</div>
</div>
2022-04-29 08:49:24 -04:00
<div class="three wide column">{{tr "Uptime"}}</div>
<div class="thirteen wide column">
2022-03-23 09:07:38 -04:00
<i class="clock icon"></i>@#secondToDate(server.State.Uptime)#@
2019-12-08 10:18:29 -05:00
</div>
</div>
2021-01-12 05:00:51 -05:00
</div>
</div>
<div class="content" v-else>
<p>@#server.Name#@</p>
2022-04-29 08:49:24 -04:00
<p>{{tr "ServerIsOffline"}}</p>
</div>
2019-12-08 10:18:29 -05:00
</div>
</div>
2019-12-08 10:18:29 -05:00
</div>
</div>
2019-12-08 03:59:58 -05:00
</div>
</div>
2019-12-08 03:59:58 -05:00
</div>
{{template "common/footer" .}}
2019-12-09 05:14:31 -05:00
<script>
2022-03-23 09:07:38 -04:00
const initData = JSON.parse('{{.Servers}}').servers;
var statusCards = new Vue({
2022-03-23 09:07:38 -04:00
el: '#app',
delimiters: ['@#', '#@'],
data: {
data: initData,
groups: [],
cache: [],
},
created() {
this.group()
},
mounted() {
$('.nezha-secondary-font.info.icon').popup({
popup: '.ui.content.popup',
exclusive: true,
});
},
methods: {
toFixed2(f) {
return f.toFixed(2)
},
2022-03-23 09:07:38 -04:00
group() {
this.groups = groupingData(this.data, "Tag")
},
2022-03-23 09:07:38 -04: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'] = '#0a94f2'
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
}
2022-03-23 09:07:38 -04:00
}
return this.cache[percent]
},
secondToDate(s) {
var d = Math.floor(s / 3600 / 24);
if (d > 0) {
2022-04-29 08:49:24 -04:00
return d + "{{tr "Day"}}"
2022-03-23 09:07:38 -04:00
}
var h = Math.floor(s / 3600 % 24);
var m = Math.floor(s / 60 % 60);
var s = Math.floor(s % 60);
return h + ":" + ("0" + m).slice(-2) + ":" + ("0" + s).slice(-2);
},
formatTimestamp(t) {
return new Date(t * 1000).toLocaleString()
},
formatByteSize(bs) {
const x = readableBytes(bs)
return x != "NaN undefined" ? x : '0B'
}
2022-03-23 09:07:38 -04:00
}
})
2022-03-23 09:07:38 -04:00
function groupingData(data, field) {
let map = {};
let dest = [];
data.forEach(item => {
if (!map[item[field]]) {
dest.push({
[field]: item[field],
data: [item]
});
map[item[field]] = item;
} else {
dest.forEach(dItem => {
if (dItem[field] == item[field]) {
dItem.data.push(item);
}
2022-03-23 09:07:38 -04:00
});
}
})
return dest;
}
2021-01-12 05:00:51 -05:00
const wsProtocol = window.location.protocol == "https:" ? "wss" : "ws"
const ws = new WebSocket(wsProtocol + '://' + window.location.host + '/ws');
ws.onopen = function (evt) {
2022-03-23 09:07:38 -04:00
$.suiAlert({
2022-04-29 08:49:24 -04:00
title: '{{tr "RealtimeChannelEstablished"}}',
description: '{{tr "GetTheLatestMonitoringDataInRealTime"}}',
2022-03-23 09:07:38 -04:00
type: 'success',
time: '2',
position: 'top-center',
});
}
ws.onmessage = function (evt) {
2022-03-23 09:07:38 -04:00
const oldServers = statusCards.servers
const data = JSON.parse(evt.data)
statusCards.servers = data.servers
for (let i = 0; i < statusCards.servers.length; i++) {
const ns = statusCards.servers[i];
if (!ns.Host) ns.live = false
else {
const lastActive = new Date(ns.LastActive).getTime()
if (data.now - lastActive > 10 * 1000) {
ns.live = false
} else {
ns.live = true
}
}
2022-03-23 09:07:38 -04:00
}
statusCards.groups = groupingData(statusCards.servers, "Tag")
}
ws.onclose = function () {
2022-03-23 09:07:38 -04:00
$.suiAlert({
2022-04-29 08:49:24 -04:00
title: '{{tr "RealtimeChannelDisconnect"}}',
description: '{{tr "CanNotGetTheLatestMonitoringDataInRealTime"}}',
2022-03-23 09:07:38 -04:00
type: 'warning',
time: '2',
position: 'top-center',
});
}
$('.ui.accordion')
2022-03-23 09:07:38 -04:00
.accordion({ "exclusive": false })
;
2019-12-09 05:14:31 -05:00
</script>
2022-03-23 09:07:38 -04:00
{{end}}