diff --git a/README.md b/README.md
index 5e9e6f6..61a19a0 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
LOGO designed by 熊大 .
-
+
:trollface: Nezha Monitoring self-hosted lightweight monitoring and operation and maintenance system. Supports system status, HTTP (SSL certificate change, upcoming expiration, expiration), TCP, Ping monitoring and alerting, execute scheduled tasks and web terminal.
diff --git a/model/api.go b/model/api.go index 50085e9..fb7a291 100644 --- a/model/api.go +++ b/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 +} diff --git a/resource/template/theme-daynight/service.html b/resource/template/theme-daynight/service.html index d3a5da7..68ba858 100644 --- a/resource/template/theme-daynight/service.html +++ b/resource/template/theme-daynight/service.html @@ -66,7 +66,7 @@ {{statusName (divU64 $service.CurrentUp (addU64 $service.CurrentUp $service.CurrentDown))}}