mirror of
https://github.com/nezhahq/nezha.git
synced 2025-02-08 20:48:13 -05:00
🐛 修复 IPv6 only 机器取 IP 问题
This commit is contained in:
parent
7d5ea7ab99
commit
1c35caf0fb
10
README.md
10
README.md
@ -1,14 +1,15 @@
|
|||||||
<div align="center" style="background-color: white">
|
<div align="center" style="background-color: white">
|
||||||
<img width="500" style="max-width:100%" src="https://raw.githubusercontent.com/naiba/nezha/master/resource/static/brand.png" title="哪吒监控">
|
<img width="500" style="max-width:100%" src="https://raw.githubusercontent.com/naiba/nezha/master/resource/static/brand.png" title="哪吒监控">
|
||||||
<br><br>
|
<br><br>
|
||||||
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.7.1&logo=github&style=for-the-badge"> <img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.6.0-brightgreen?style=for-the-badge&logo=linux">
|
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.7.2&logo=github&style=for-the-badge"> <img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.6.0-brightgreen?style=for-the-badge&logo=linux">
|
||||||
<br>
|
<br>
|
||||||
<p>:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>
|
<p>:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
\>> 交流论坛:[打杂社区](https://daza.net/c/nezha) (Lemmy)
|
\>> 交流论坛:[打杂社区](https://daza.net/c/nezha) (Lemmy)
|
||||||
|
|
||||||
\>> QQ 交流群:872069346 **加群要求:已搭建好哪吒监控 & 有 2+ 服务器**
|
\>> QQ 交流群:872069346 **加群要求:已搭建好哪吒监控 & 有 2+ 服务器**<br>
|
||||||
|
群友互助/服务器交流,作者不答疑,找 naiba 请至论坛发帖
|
||||||
|
|
||||||
\>> [我们的用户](https://www.google.com/search?q="powered+by+哪吒监控%7C哪吒面板"&filter=0) (Google)
|
\>> [我们的用户](https://www.google.com/search?q="powered+by+哪吒监控%7C哪吒面板"&filter=0) (Google)
|
||||||
|
|
||||||
@ -22,17 +23,18 @@
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -sSL https://raw.githubusercontent.com/naiba/nezha/master/script/fetch.sh | bash
|
curl -sSL https://raw.githubusercontent.com/naiba/nezha/master/script/fetch.sh | bash
|
||||||
/opt/nezha/nezha.sh
|
sudo /opt/nezha/nezha.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
国内镜像加速:
|
国内镜像加速:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -sSL https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/fetch.sh | CN=true bash
|
curl -sSL https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/fetch.sh | CN=true bash
|
||||||
CN=true /opt/nezha/nezha.sh
|
CN=true sudo /opt/nezha/nezha.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
再次运行仅需:
|
再次运行仅需:
|
||||||
|
|
||||||
```
|
```
|
||||||
/opt/nezha/nezha.sh
|
/opt/nezha/nezha.sh
|
||||||
```
|
```
|
||||||
|
@ -108,8 +108,13 @@ func resolveIP(addr string, ipv6 bool) (string, error) {
|
|||||||
}
|
}
|
||||||
m.RecursionDesired = true
|
m.RecursionDesired = true
|
||||||
|
|
||||||
|
dnsServer := "2606:4700:4700::1111"
|
||||||
|
if !ipv6 {
|
||||||
|
dnsServer = "1.1.1.1"
|
||||||
|
}
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
r, _, err := c.Exchange(m, net.JoinHostPort("1.1.1.1", "53"))
|
r, _, err := c.Exchange(m, net.JoinHostPort(dnsServer, "53"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
522
resource/template/theme-default/home.html
vendored
522
resource/template/theme-default/home.html
vendored
@ -1,257 +1,285 @@
|
|||||||
{{define "theme-default/home"}}
|
{{define "theme-default/home"}} {{template "common/header" .}} {{if ts
|
||||||
{{template "common/header" .}}
|
.CustomCode}} {{.CustomCode|safe}} {{end}} {{template "common/menu" .}}
|
||||||
{{if ts .CustomCode}}
|
|
||||||
{{.CustomCode|safe}}
|
|
||||||
{{end}}
|
|
||||||
{{template "common/menu" .}}
|
|
||||||
<div class="nb-container">
|
<div class="nb-container">
|
||||||
<div class="ui container">
|
<div class="ui container">
|
||||||
<div id="app">
|
<div id="app">
|
||||||
|
<div class="ui styled fluid accordion" v-for="group in groups">
|
||||||
<div class="ui styled fluid accordion" v-for="group in groups">
|
<div class="active title">
|
||||||
<div class="active title"><i class="dropdown icon"></i>@#(group.Tag!==''?group.Tag:'默认')#@</div>
|
<i class="dropdown icon"></i>@#(group.Tag!==''?group.Tag:'默认')#@
|
||||||
<div class="active content">
|
|
||||||
<div class="ui four stackable status cards">
|
|
||||||
<div v-for='server in group.data' :id="server.ID" class="ui card">
|
|
||||||
<div class="content" v-if='server.Host' style="margin-top: 10px;padding-bottom: 5px">
|
|
||||||
<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
|
|
||||||
v-if='server.Host.Platform == "windows"' class="windows icon"></i><i
|
|
||||||
v-if='server.Host.Platform == "freebsd"' class="freebsd icon"></i>@#server.Name
|
|
||||||
+
|
|
||||||
(server.live?'':' [已离线]')#@
|
|
||||||
<i class="yellow info circle icon"></i>
|
|
||||||
<div class='ui content popup' style="margin-bottom: 0">
|
|
||||||
系统:@#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>
|
|
||||||
硬盘:@#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>
|
|
||||||
流量:<i
|
|
||||||
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>
|
|
||||||
启动:@# formatTimestamp(server.Host.BootTime) #@<br>
|
|
||||||
活动:@# new Date(server.LastActive).toLocaleString() #@<br>
|
|
||||||
版本:@#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">
|
|
||||||
<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>
|
|
||||||
<div class="three wide column">内存</div>
|
|
||||||
<div class="thirteen wide column">
|
|
||||||
<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>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="three wide column">交换</div>
|
|
||||||
<div class="thirteen wide column">
|
|
||||||
<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>
|
|
||||||
<div class="three wide column">网络</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>
|
|
||||||
<div class="three wide column">硬盘</div>
|
|
||||||
<div class="thirteen wide column">
|
|
||||||
<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>
|
|
||||||
<div class="three wide column">在线</div>
|
|
||||||
<div class="thirteen wide column">
|
|
||||||
<i class="clock icon"></i>@#secondToDate(server.State.Uptime)#@
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="content" v-else>
|
|
||||||
<p>@#server.Name#@</p>
|
|
||||||
<p>节点已离线</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</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">
|
||||||
|
<div
|
||||||
|
class="content"
|
||||||
|
v-if="server.Host"
|
||||||
|
style="margin-top: 10px; padding-bottom: 5px"
|
||||||
|
>
|
||||||
|
<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
|
||||||
|
v-if='server.Host.Platform == "windows"'
|
||||||
|
class="windows icon"
|
||||||
|
></i
|
||||||
|
><i
|
||||||
|
v-if='server.Host.Platform == "freebsd"'
|
||||||
|
class="freebsd icon"
|
||||||
|
></i
|
||||||
|
>@#server.Name + (server.live?'':' [已离线]')#@
|
||||||
|
<i class="yellow info circle icon"></i>
|
||||||
|
<div class="ui content popup" style="margin-bottom: 0">
|
||||||
|
系统:@#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 />
|
||||||
|
硬盘:@#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 />
|
||||||
|
流量:<i
|
||||||
|
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 />
|
||||||
|
启动:@# formatTimestamp(server.Host.BootTime) #@<br />
|
||||||
|
活动:@# new Date(server.LastActive).toLocaleString() #@<br />
|
||||||
|
版本:@#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">
|
||||||
|
<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>
|
||||||
|
<div class="three wide column">内存</div>
|
||||||
|
<div class="thirteen wide column">
|
||||||
|
<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
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="three wide column">交换</div>
|
||||||
|
<div class="thirteen wide column">
|
||||||
|
<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>
|
||||||
|
<div class="three wide column">网络</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>
|
||||||
|
<div class="three wide column">硬盘</div>
|
||||||
|
<div class="thirteen wide column">
|
||||||
|
<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>
|
||||||
|
<div class="three wide column">在线</div>
|
||||||
|
<div class="thirteen wide column">
|
||||||
|
<i class="clock icon"></i
|
||||||
|
>@#secondToDate(server.State.Uptime)#@
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="content" v-else>
|
||||||
|
<p>@#server.Name#@</p>
|
||||||
|
<p>节点已离线</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{template "common/footer" .}}
|
{{template "common/footer" .}}
|
||||||
<script>
|
<script>
|
||||||
const initData = {{.Servers}};
|
const initData = {{.Servers}};
|
||||||
var statusCards = new Vue({
|
var statusCards = new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
delimiters: ['@#', '#@'],
|
delimiters: ['@#', '#@'],
|
||||||
data: {
|
data: {
|
||||||
data: initData,
|
data: initData,
|
||||||
groups: [],
|
groups: [],
|
||||||
cache: [],
|
cache: [],
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.group()
|
this.group()
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
$('.yellow.info.icon').popup({
|
$('.yellow.info.icon').popup({
|
||||||
popup: '.ui.content.popup',
|
popup: '.ui.content.popup',
|
||||||
exclusive: true,
|
exclusive: true,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
group() {
|
group() {
|
||||||
this.groups = groupingData(this.data, "Tag")
|
this.groups = groupingData(this.data, "Tag")
|
||||||
console.log(this.groups)
|
},
|
||||||
},
|
formatPercent(live, used, total) {
|
||||||
formatPercent(live, used, total) {
|
const percent = live ? (parseInt(used / total * 100) || 0) : -1
|
||||||
const percent = live ? (parseInt(used / total * 100) || 0) : -1
|
if (!this.cache[percent]) {
|
||||||
if (!this.cache[percent]) {
|
this.cache[percent] = {
|
||||||
this.cache[percent] = {
|
class: {
|
||||||
class: {
|
ui: true,
|
||||||
ui: true,
|
progress: true,
|
||||||
progress: true,
|
},
|
||||||
},
|
style: {
|
||||||
style: {
|
'transition-duration': '300ms',
|
||||||
'transition-duration': '300ms',
|
'min-width': 'unset',
|
||||||
'min-width': 'unset',
|
width: percent + '% !important',
|
||||||
width: percent + '% !important',
|
},
|
||||||
},
|
percent,
|
||||||
percent,
|
}
|
||||||
}
|
if (percent < 0) {
|
||||||
if (percent < 0) {
|
this.cache[percent].style['background-color'] = 'slategray'
|
||||||
this.cache[percent].style['background-color'] = 'slategray'
|
this.cache[percent].class.offline = true
|
||||||
this.cache[percent].class.offline = true
|
} else if (percent < 51) {
|
||||||
} else if (percent < 51) {
|
this.cache[percent].style['background-color'] = 'rgb(0, 235, 139)'
|
||||||
this.cache[percent].style['background-color'] = 'rgb(0, 235, 139)'
|
this.cache[percent].class.fine = true
|
||||||
this.cache[percent].class.fine = true
|
} else if (percent < 81) {
|
||||||
} else if (percent < 81) {
|
this.cache[percent].style['background-color'] = 'orange'
|
||||||
this.cache[percent].style['background-color'] = 'orange'
|
this.cache[percent].class.warning = true
|
||||||
this.cache[percent].class.warning = true
|
} else {
|
||||||
} else {
|
this.cache[percent].style['background-color'] = 'crimson'
|
||||||
this.cache[percent].style['background-color'] = 'crimson'
|
this.cache[percent].class.error = true
|
||||||
this.cache[percent].class.error = true
|
}
|
||||||
}
|
}
|
||||||
}
|
return this.cache[percent]
|
||||||
return this.cache[percent]
|
},
|
||||||
},
|
secondToDate(s) {
|
||||||
secondToDate(s) {
|
var d = Math.floor(s / 3600 / 24);
|
||||||
var d = Math.floor(s / 3600 / 24);
|
if (d > 0) {
|
||||||
if (d > 0) {
|
return d + "天"
|
||||||
return d + "天"
|
}
|
||||||
}
|
var h = Math.floor(s / 3600 % 24);
|
||||||
var h = Math.floor(s / 3600 % 24);
|
var m = Math.floor(s / 60 % 60);
|
||||||
var m = Math.floor(s / 60 % 60);
|
var s = Math.floor(s % 60);
|
||||||
var s = Math.floor(s % 60);
|
return h + ":" + ("0" + m).slice(-2) + ":" + ("0" + s).slice(-2);
|
||||||
return h + ":" + ("0" + m).slice(-2) + ":" + ("0" + s).slice(-2);
|
},
|
||||||
},
|
formatTimestamp(t) {
|
||||||
formatTimestamp(t) {
|
return new Date(t * 1000).toLocaleString()
|
||||||
return new Date(t * 1000).toLocaleString()
|
},
|
||||||
},
|
formatByteSize(bs) {
|
||||||
formatByteSize(bs) {
|
const x = readableBytes(bs)
|
||||||
const x = readableBytes(bs)
|
return x != "NaN undefined" ? x : '0 KB'
|
||||||
return x != "NaN undefined" ? x : '0 KB'
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
|
|
||||||
function groupingData(data, filed) {
|
function groupingData(data, filed) {
|
||||||
let map = {};
|
let map = {};
|
||||||
|
let dest = [];
|
||||||
|
data.forEach(item => {
|
||||||
|
if (!map[item[filed]]) {
|
||||||
|
dest.push({
|
||||||
|
[filed]: item[filed],
|
||||||
|
data: [item]
|
||||||
|
});
|
||||||
|
map[item[filed]] = item;
|
||||||
|
} else {
|
||||||
|
dest.forEach(dItem => {
|
||||||
|
if (dItem[filed] == item[filed]) {
|
||||||
|
dItem.data.push(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
let dest = [];
|
const wsProtocol = window.location.protocol == "https:" ? "wss" : "ws"
|
||||||
|
const ws = new WebSocket(wsProtocol + '://' + window.location.host + '/ws');
|
||||||
data.forEach(item => {
|
ws.onopen = function (evt) {
|
||||||
if (!map[item[filed]]) {
|
$.suiAlert({
|
||||||
dest.push({
|
title: '实时通道建立',
|
||||||
[filed]: item[filed],
|
description: '可以实时获取最新监控数据啦',
|
||||||
|
type: 'success',
|
||||||
data: [item]
|
time: '2',
|
||||||
|
position: 'top-center',
|
||||||
});
|
});
|
||||||
|
}
|
||||||
map[item[filed]] = item;
|
ws.onmessage = function (evt) {
|
||||||
|
const oldServers = statusCards.servers
|
||||||
} else {
|
statusCards.servers = JSON.parse(evt.data)
|
||||||
dest.forEach(dItem => {
|
for (let i = 0; i < statusCards.servers.length; i++) {
|
||||||
if (dItem[filed] == item[filed]) {
|
const ns = statusCards.servers[i];
|
||||||
dItem.data.push(item);
|
if (!ns.Host) ns.live = false
|
||||||
|
else {
|
||||||
}
|
const lastActive = new Date(ns.LastActive).getTime()
|
||||||
|
if (Date.now() - lastActive > 20 * 1000) {
|
||||||
});
|
ns.live = false
|
||||||
|
} else {
|
||||||
}
|
ns.live = true
|
||||||
|
}
|
||||||
})
|
}
|
||||||
|
}
|
||||||
return dest;
|
statusCards.groups = groupingData(statusCards.servers, "Tag")
|
||||||
|
}
|
||||||
}
|
ws.onclose = function () {
|
||||||
|
$.suiAlert({
|
||||||
const wsProtocol = window.location.protocol == "https:" ? "wss" : "ws"
|
title: '实时通道断开',
|
||||||
const ws = new WebSocket(wsProtocol + '://' + window.location.host + '/ws');
|
description: '无法实时获取最新监控数据咯',
|
||||||
ws.onopen = function (evt) {
|
type: 'warning',
|
||||||
$.suiAlert({
|
time: '2',
|
||||||
title: '实时通道建立',
|
position: 'top-center',
|
||||||
description: '可以实时获取最新监控数据啦',
|
});
|
||||||
type: 'success',
|
}
|
||||||
time: '2',
|
$('.ui.accordion')
|
||||||
position: 'top-center',
|
.accordion({"exclusive": false})
|
||||||
});
|
;
|
||||||
}
|
|
||||||
ws.onmessage = function (evt) {
|
|
||||||
const oldServers = statusCards.servers
|
|
||||||
statusCards.servers = JSON.parse(evt.data)
|
|
||||||
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 (Date.now() - lastActive > 20 * 1000) {
|
|
||||||
ns.live = false
|
|
||||||
} else {
|
|
||||||
ns.live = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
statusCards.groups = groupingData(statusCards.servers, "Tag")
|
|
||||||
}
|
|
||||||
ws.onclose = function () {
|
|
||||||
$.suiAlert({
|
|
||||||
title: '实时通道断开',
|
|
||||||
description: '无法实时获取最新监控数据咯',
|
|
||||||
type: 'warning',
|
|
||||||
time: '2',
|
|
||||||
position: 'top-center',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
$('.ui.accordion')
|
|
||||||
.accordion({"exclusive": false})
|
|
||||||
;
|
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
pb "github.com/naiba/nezha/proto"
|
pb "github.com/naiba/nezha/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "v0.7.1" // !!记得修改 README 中的 badge 版本!!
|
var Version = "v0.7.2" // !!记得修改 README 中的 badge 版本!!
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SnapshotDelay = 3
|
SnapshotDelay = 3
|
||||||
|
@ -275,7 +275,7 @@ func (ss *ServiceSentinel) worker() {
|
|||||||
}
|
}
|
||||||
stateStr := getStateStr(upPercent)
|
stateStr := getStateStr(upPercent)
|
||||||
if Conf.Debug {
|
if Conf.Debug {
|
||||||
log.Println(ss.monitors[mh.MonitorID].Target, stateStr, "Agent:", r.Reporter, "Successful:", mh.Successful, "Response:", mh.Data)
|
log.Println("服务监控上报:", ss.monitors[mh.MonitorID].Target, stateStr, "上报者:", r.Reporter, "是否正常:", mh.Successful, "请求输出:", mh.Data)
|
||||||
}
|
}
|
||||||
if stateStr == "故障" || stateStr != ss.lastStatus[mh.MonitorID] {
|
if stateStr == "故障" || stateStr != ss.lastStatus[mh.MonitorID] {
|
||||||
ss.monitorsLock.RLock()
|
ss.monitorsLock.RLock()
|
||||||
|
Loading…
Reference in New Issue
Block a user