mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
🚸 improve: 优化agent取双栈IP、服务状态页面展示策略
This commit is contained in:
parent
a41c792577
commit
345511e90f
@ -71,6 +71,30 @@ func ServeWeb(port uint) {
|
||||
today := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
|
||||
return today.AddDate(0, 0, i-29).Format("1月2号")
|
||||
},
|
||||
"className": func(percent float32) string {
|
||||
if percent == 0 {
|
||||
return ""
|
||||
}
|
||||
if percent > 95 {
|
||||
return "good"
|
||||
}
|
||||
if percent > 80 {
|
||||
return "warning"
|
||||
}
|
||||
return "danger"
|
||||
},
|
||||
"statusName": func(percent float32) string {
|
||||
if percent == 0 {
|
||||
return "无数据"
|
||||
}
|
||||
if percent > 95 {
|
||||
return "良好"
|
||||
}
|
||||
if percent > 80 {
|
||||
return "低可用"
|
||||
}
|
||||
return "故障"
|
||||
},
|
||||
})
|
||||
r.Static("/static", "resource/static")
|
||||
r.LoadHTMLGlob("resource/template/**/*")
|
||||
|
@ -8,29 +8,20 @@
|
||||
<div class="ui grid">
|
||||
<div class="three wide column">
|
||||
<p>{{$service.Monitor.Name}}</p>
|
||||
<p>30天在线率{{divU64 $service.TotalDown (addU64 $service.TotalUp $service.TotalDown)}}%</p>
|
||||
<p>30天在线率{{divU64 $service.TotalUp (addU64 $service.TotalUp $service.TotalDown)}}%</p>
|
||||
</div>
|
||||
<div class="eleven wide column">
|
||||
{{range $i,$d := $service.Delay}}
|
||||
<div class="ui icon button{{if gt (add (index $service.Up $i) (index $service.Down $i)) 0}}
|
||||
{{if gt (div (index $service.Down $i) (add (index $service.Up $i) (index $service.Down $i))) 30.0}}danger
|
||||
{{else if gt (div (index $service.Down $i) (add (index $service.Up $i) (index $service.Down $i))) 10.0}}
|
||||
warning{{else}}good{{end}}
|
||||
{{end}}" data-tooltip="{{dayBefore $i}},平均延迟:{{$d}}ms">
|
||||
<div class="ui icon button {{className (div (index $service.Up $i) (add (index $service.Up $i) (index $service.Down $i)))}}"
|
||||
data-tooltip="{{dayBefore $i}},平均延迟:{{$d}}ms">
|
||||
<i class="delay"></i>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="two wide column round{{if gt (addU64 $service.TotalUp $service.TotalDown) 0}}
|
||||
{{if gt (divU64 $service.TotalDown (addU64 $service.TotalUp $service.TotalDown)) 30.0}}danger{{else if gt (divU64 $service.TotalDown (addU64 $service.TotalUp $service.TotalDown)) 10.0}}warning{{else}}good{{end}}
|
||||
{{end}}">
|
||||
<div
|
||||
class="two wide column round {{className (div (index $service.Up 29) (add (index $service.Up 29) (index $service.Down 29)))}}">
|
||||
<i></i>
|
||||
{{if gt (addU64 $service.TotalUp $service.TotalDown) 0}}
|
||||
{{if gt (divU64 $service.TotalDown (addU64 $service.TotalUp $service.TotalDown)) 30.0}}故障
|
||||
{{else if gt (divU64 $service.TotalDown (addU64 $service.TotalUp $service.TotalDown)) 10.0}}
|
||||
低可用{{else}}良好{{end}}
|
||||
{{else}}无数据
|
||||
{{end}}
|
||||
{{statusName (div (index $service.Up 29) (add (index $service.Up 29) (index $service.Down 29)))}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui divider"></div>
|
||||
|
@ -135,6 +135,7 @@
|
||||
<footer>
|
||||
<p style="text-align:center;padding: 15px;">Powered by <a href="https://github.com/naiba/nezha">哪吒面板</a> build ·
|
||||
{{.Version}}
|
||||
<a href="/service">服务状态</a>
|
||||
<a href="/server">管理后台</a>
|
||||
</p>
|
||||
</footer>
|
||||
|
33
resource/template/theme-hotaru/service.html
Normal file
33
resource/template/theme-hotaru/service.html
Normal file
@ -0,0 +1,33 @@
|
||||
{{define "theme-hotaru/service"}}
|
||||
{{template "common/header" .}}
|
||||
{{template "common/menu" .}}
|
||||
<div class="nb-container">
|
||||
<div class="ui container">
|
||||
<div class="ui segment service-status">
|
||||
{{range $service := .Services}}
|
||||
<div class="ui grid">
|
||||
<div class="three wide column">
|
||||
<p>{{$service.Monitor.Name}}</p>
|
||||
<p>30天在线率{{divU64 $service.TotalUp (addU64 $service.TotalUp $service.TotalDown)}}%</p>
|
||||
</div>
|
||||
<div class="eleven wide column">
|
||||
{{range $i,$d := $service.Delay}}
|
||||
<div class="ui icon button {{className (div (index $service.Up $i) (add (index $service.Up $i) (index $service.Down $i)))}}"
|
||||
data-tooltip="{{dayBefore $i}},平均延迟:{{$d}}ms">
|
||||
<i class="delay"></i>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
<div
|
||||
class="two wide column round {{className (div (index $service.Up 29) (add (index $service.Up 29) (index $service.Down 29)))}}">
|
||||
<i></i>
|
||||
{{statusName (div (index $service.Up 29) (add (index $service.Up 29) (index $service.Down 29)))}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui divider"></div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{template "common/footer" .}}
|
||||
{{end}}
|
@ -26,7 +26,7 @@ var SortedServerList []*model.Server
|
||||
|
||||
var ServerLock sync.RWMutex
|
||||
|
||||
var Version = "v0.2.0"
|
||||
var Version = "v0.2.1"
|
||||
|
||||
func ReSortServer() {
|
||||
SortedServerList = []*model.Server{}
|
||||
|
@ -43,6 +43,14 @@ func GetHost() *model.Host {
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
json.Unmarshal(body, &ip)
|
||||
}
|
||||
|
||||
resp, err = http.Get("https://api-ipv6.ip.sb/ip")
|
||||
if err == nil {
|
||||
defer resp.Body.Close()
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
ip.IP = fmt.Sprintf("ip(v4: %s, v6: %s)", ip.IP, body)
|
||||
}
|
||||
|
||||
return &model.Host{
|
||||
Platform: hi.OS,
|
||||
PlatformVersion: hi.PlatformVersion,
|
||||
|
@ -87,7 +87,8 @@ func (s *NezhaHandler) ReportSystemInfo(c context.Context, r *pb.Host) (*pb.Rece
|
||||
host := model.PB2Host(r)
|
||||
dao.ServerLock.RLock()
|
||||
defer dao.ServerLock.RUnlock()
|
||||
if dao.ServerList[clientID].Host != nil &&
|
||||
if dao.Conf.EnableIPChangeNotification &&
|
||||
dao.ServerList[clientID].Host != nil &&
|
||||
dao.ServerList[clientID].Host.IP != "" &&
|
||||
host.IP != "" &&
|
||||
dao.ServerList[clientID].Host.IP != host.IP {
|
||||
|
Loading…
Reference in New Issue
Block a user