mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
fix: service total uptime rate close #191
This commit is contained in:
25
model/api.go
25
model/api.go
@@ -2,11 +2,32 @@ package model
|
||||
|
||||
type ServiceItemResponse struct {
|
||||
Monitor *Monitor
|
||||
TotalUp uint64
|
||||
TotalDown uint64
|
||||
CurrentUp uint64
|
||||
CurrentDown uint64
|
||||
Delay *[30]float32
|
||||
Up *[30]int
|
||||
Down *[30]int
|
||||
}
|
||||
|
||||
func sum[T int | float32](slice *[30]T) T {
|
||||
if slice == nil {
|
||||
return 0
|
||||
}
|
||||
var sum T
|
||||
for _, v := range *slice {
|
||||
sum += v
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func (r ServiceItemResponse) TotalUp() int {
|
||||
return sum(r.Up)
|
||||
}
|
||||
|
||||
func (r ServiceItemResponse) TotalDown() int {
|
||||
return sum(r.Down)
|
||||
}
|
||||
|
||||
func (r ServiceItemResponse) TotalUptime() float32 {
|
||||
return float32(r.TotalUp()) / (float32(r.TotalUp() + r.TotalDown())) * 100
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user