dashboard v0.2.4 优化当前状态数据

This commit is contained in:
naiba 2021-01-17 11:44:50 +08:00
parent 998724112e
commit 904b926187
6 changed files with 46 additions and 36 deletions

View File

@ -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` **重大更新**

View File

@ -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,

View File

@ -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;
}

View File

@ -24,15 +24,11 @@
<td class="ui center aligned">{{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}},平均延迟:{{float32f $d}}ms">
<i class="delay"></i>
</div> {{end}}
</td>
<td class="ui center aligned">
<div
class="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>
<td class="ui center aligned delay-today">
<i class="delay-today {{className (divU64 $service.CurrentUp (addU64 $service.CurrentUp $service.CurrentDown))}}"></i>
{{statusName (divU64 $service.CurrentUp (addU64 $service.CurrentUp $service.CurrentDown))}}
</td>
</tr> {{end}}
</tbody>

View File

@ -24,15 +24,11 @@
<td class="ui center aligned">{{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}},平均延迟:{{float32f $d}}ms">
<i class="delay"></i>
</div> {{end}}
</td>
<td class="ui center aligned">
<div
class="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>
<td class="ui center aligned delay-today">
<i class="delay-today {{className (divU64 $service.CurrentUp (addU64 $service.CurrentUp $service.CurrentDown))}}"></i>
{{statusName (divU64 $service.CurrentUp (addU64 $service.CurrentUp $service.CurrentDown))}}
</td>
</tr> {{end}}
</tbody>

View File

@ -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{}