2020-12-30 02:22:17 +01:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
numberOfHoursInTenDays = 10 * 24
|
|
|
|
sevenDays = 7 * 24 * time.Hour
|
|
|
|
)
|
|
|
|
|
|
|
|
// Uptime is the struct that contains the relevant data for calculating the uptime as well as the uptime itself
|
2021-04-18 06:51:47 +02:00
|
|
|
// and some other statistics
|
2020-12-30 02:22:17 +01:00
|
|
|
type Uptime struct {
|
2021-04-18 07:01:10 +02:00
|
|
|
LastSevenDays float64 `json:"7d"` // Uptime percentage over the past 7 days
|
|
|
|
LastTwentyFourHours float64 `json:"24h"` // Uptime percentage over the past 24 hours
|
|
|
|
LastHour float64 `json:"1h"` // Uptime percentage over the past hour
|
2020-12-30 02:22:17 +01:00
|
|
|
|
2021-03-06 21:19:35 +01:00
|
|
|
// SuccessfulExecutionsPerHour is a map containing the number of successes (value)
|
|
|
|
// for every hourly unix timestamps (key)
|
2021-04-18 06:51:47 +02:00
|
|
|
// Deprecated
|
2021-03-06 21:19:35 +01:00
|
|
|
SuccessfulExecutionsPerHour map[int64]uint64 `json:"-"`
|
2021-02-03 05:06:34 +01:00
|
|
|
|
2021-03-06 21:19:35 +01:00
|
|
|
// TotalExecutionsPerHour is a map containing the total number of checks (value)
|
|
|
|
// for every hourly unix timestamps (key)
|
2021-04-18 06:51:47 +02:00
|
|
|
// Deprecated
|
2021-03-06 21:19:35 +01:00
|
|
|
TotalExecutionsPerHour map[int64]uint64 `json:"-"`
|
2021-04-18 06:51:47 +02:00
|
|
|
|
|
|
|
// HourlyStatistics is a map containing metrics collected (value) for every hourly unix timestamps (key)
|
|
|
|
HourlyStatistics map[int64]*HourlyUptimeStatistics `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// HourlyUptimeStatistics is a struct containing all metrics collected over the course of an hour
|
|
|
|
type HourlyUptimeStatistics struct {
|
|
|
|
TotalExecutions uint64 // Total number of checks
|
|
|
|
SuccessfulExecutions uint64 // Number of successful executions
|
|
|
|
TotalExecutionsResponseTime uint64 // Total response time for all executions
|
2020-12-30 02:22:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewUptime creates a new Uptime
|
|
|
|
func NewUptime() *Uptime {
|
|
|
|
return &Uptime{
|
2021-04-18 06:51:47 +02:00
|
|
|
HourlyStatistics: make(map[int64]*HourlyUptimeStatistics),
|
2020-12-30 02:22:17 +01:00
|
|
|
}
|
|
|
|
}
|