feat: Added uptime calculation method

This commit is contained in:
2025-08-12 18:58:09 +03:00
parent dbe321562e
commit cb03e828ee
3 changed files with 31 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
package model
import "math"
type HTTPConfig struct {
Method string `json:"method"`
Headers map[string]string `json:"headers"`
@@ -45,3 +47,29 @@ func (s Service) CountLastStatuses(status StatusCode) uint {
return count
}
func (s Service) CalculateUptimePercent() float64 {
var uptime float64
if len(s.Statuses) == 0 {
return uptime
}
var countOfOkStatus int
for i := range s.Statuses {
if s.Statuses[i].Status == StatusOK {
countOfOkStatus++
}
}
if countOfOkStatus == 0 {
return uptime
}
sla := 100 - (float64(len(s.Statuses)) / float64(countOfOkStatus))
ratio := math.Pow(10, float64(2))
uptime = math.Round(sla*ratio) / ratio
return uptime
}