feat: Added uptime calculation method
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user