diff --git a/README.md b/README.md index 3a3f0be..4ceb7ce 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,7 @@ URL 里面也可放置占位符,请求时会进行简单的字符串替换。 ## 变更日志 -最新:`dashboard 0.2.3` `agent 0.2.3`,只记录最后一次更新导致必须更新面板的说明。 +最新:`dashboard 0.2.4` `agent 0.2.3`,只记录最后一次更新导致必须更新面板的说明。 - `dashboard 0.2.0` `agent 0.2.0` **重大更新** diff --git a/cmd/dashboard/controller/common_page.go b/cmd/dashboard/controller/common_page.go index 3954204..7198032 100644 --- a/cmd/dashboard/controller/common_page.go +++ b/cmd/dashboard/controller/common_page.go @@ -25,12 +25,14 @@ func (cp *commonPage) serve() { } type ServiceItem struct { - Monitor model.Monitor - TotalUp uint64 - TotalDown uint64 - Delay *[30]float32 - Up *[30]int - Down *[30]int + Monitor model.Monitor + TotalUp uint64 + TotalDown uint64 + CurrentUp uint64 + CurrentDown uint64 + Delay *[30]float32 + Up *[30]int + Down *[30]int } func (p *commonPage) service(c *gin.Context) { @@ -52,10 +54,13 @@ func (p *commonPage) service(c *gin.Context) { } // 整合数据 + todayStatus := make(map[uint64][]bool) for i := 0; i < len(mhs); i++ { dayIndex := 29 if mhs[i].CreatedAt.Before(today) { dayIndex = 28 - (int(today.Sub(mhs[i].CreatedAt).Hours()) / 24) + } else { + todayStatus[mhs[i].MonitorID] = append(todayStatus[mhs[i].MonitorID], mhs[i].Successful) } if mhs[i].Successful { msm[mhs[i].MonitorID].TotalUp++ @@ -67,6 +72,17 @@ func (p *commonPage) service(c *gin.Context) { } } + // 当日最后 20 个采样作为当前状态 + for _, m := range msm { + for i := len(todayStatus[m.Monitor.ID]) - 1; i >= 0 && i >= (len(todayStatus[m.Monitor.ID])-1-20); i-- { + if todayStatus[m.Monitor.ID][i] { + m.CurrentUp++ + } else { + m.CurrentDown++ + } + } + } + c.HTML(http.StatusOK, "theme-"+dao.Conf.Site.Theme+"/service", mygin.CommonEnvironment(c, gin.H{ "Title": "服务状态", "Services": msm, diff --git a/resource/static/main.css b/resource/static/main.css index ff357f3..ca722ff 100644 --- a/resource/static/main.css +++ b/resource/static/main.css @@ -78,26 +78,28 @@ font-weight: 700; } -.service-status .danger.button { - background-color: crimson; +.service-status .delay-today { + display: flex; + align-items: center; } -.service-status .good.button { - background-color: rgb(0, 235, 139); +.service-status .delay-today>i { + display: inline-block; + width: 1.2em; + height: 1.2em; + border-radius: .6em; + background-color: grey; + margin-right: .3em; } -.service-status .warning.button { - background-color: orange; +.service-status .danger { + background-color: crimson !important; } -.service-status .danger>i { - background-color: crimson; +.service-status .good { + background-color: rgb(0, 235, 139) !important; } -.service-status .good>i { - background-color: rgb(0, 235, 139); -} - -.service-status .warning>i { - background-color: orange; +.service-status .warning { + background-color: orange !important; } \ No newline at end of file diff --git a/resource/template/theme-default/service.html b/resource/template/theme-default/service.html index 1c60088..df3fb03 100644 --- a/resource/template/theme-default/service.html +++ b/resource/template/theme-default/service.html @@ -24,15 +24,11 @@ {{range $i,$d := $service.Delay}}
-
{{end}} - -
- - {{statusName (div (index $service.Up 29) (add (index $service.Up 29) (index $service.Down 29)))}} -
+ + + {{statusName (divU64 $service.CurrentUp (addU64 $service.CurrentUp $service.CurrentDown))}} {{end}} diff --git a/resource/template/theme-hotaru/service.html b/resource/template/theme-hotaru/service.html index 8bffde2..7a89532 100644 --- a/resource/template/theme-hotaru/service.html +++ b/resource/template/theme-hotaru/service.html @@ -24,15 +24,11 @@ {{range $i,$d := $service.Delay}}
-
{{end}} - -
- - {{statusName (div (index $service.Up 29) (add (index $service.Up 29) (index $service.Down 29)))}} -
+ + + {{statusName (divU64 $service.CurrentUp (addU64 $service.CurrentUp $service.CurrentDown))}} {{end}} diff --git a/service/dao/dao.go b/service/dao/dao.go index d81b9ee..69b96d0 100644 --- a/service/dao/dao.go +++ b/service/dao/dao.go @@ -26,7 +26,7 @@ var SortedServerList []*model.Server var ServerLock sync.RWMutex -var Version = "v0.2.3" +var Version = "v0.2.4" func ReSortServer() { SortedServerList = []*model.Server{}