mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 20:52:33 +02:00
fix incorrect uptime history data
This commit is contained in:
parent
9f54f40f5a
commit
964e94b3ba
2 changed files with 22 additions and 12 deletions
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type (
|
type (
|
||||||
StatusByAlias struct {
|
StatusByAlias struct {
|
||||||
Map map[string]health.WithHealthInfo
|
Map map[string]map[string]any
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
}
|
}
|
||||||
Status struct {
|
Status struct {
|
||||||
|
@ -36,10 +36,9 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStatuses(ctx context.Context, _ *StatusByAlias) (*StatusByAlias, error) {
|
func getStatuses(ctx context.Context, _ *StatusByAlias) (*StatusByAlias, error) {
|
||||||
now := time.Now()
|
|
||||||
return &StatusByAlias{
|
return &StatusByAlias{
|
||||||
Map: routequery.HealthInfo(),
|
Map: routequery.HealthInfo(),
|
||||||
Timestamp: now,
|
Timestamp: time.Now(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +51,8 @@ func aggregateStatuses(entries []*StatusByAlias, query url.Values) (int, Aggrega
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
for alias, status := range entry.Map {
|
for alias, status := range entry.Map {
|
||||||
statuses[alias] = append(statuses[alias], &Status{
|
statuses[alias] = append(statuses[alias], &Status{
|
||||||
Status: status.Status(),
|
Status: status["status"].(health.Status),
|
||||||
Latency: status.Latency(),
|
Latency: status["latency"].(time.Duration),
|
||||||
Timestamp: entry.Timestamp,
|
Timestamp: entry.Timestamp,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,21 +29,32 @@ func getHealthInfo(r route.Route) map[string]string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getHealthInfoRaw(r route.Route) map[string]any {
|
||||||
|
mon := r.HealthMonitor()
|
||||||
|
if mon == nil {
|
||||||
|
return map[string]any{
|
||||||
|
"status": health.StatusUnknown,
|
||||||
|
"latency": time.Duration(0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map[string]any{
|
||||||
|
"status": mon.Status(),
|
||||||
|
"latency": mon.Latency(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func HealthMap() map[string]map[string]string {
|
func HealthMap() map[string]map[string]string {
|
||||||
healthMap := make(map[string]map[string]string)
|
healthMap := make(map[string]map[string]string, routes.NumRoutes())
|
||||||
routes.RangeRoutes(func(alias string, r route.Route) {
|
routes.RangeRoutes(func(alias string, r route.Route) {
|
||||||
healthMap[alias] = getHealthInfo(r)
|
healthMap[alias] = getHealthInfo(r)
|
||||||
})
|
})
|
||||||
return healthMap
|
return healthMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func HealthInfo() map[string]health.WithHealthInfo {
|
func HealthInfo() map[string]map[string]any {
|
||||||
healthMap := make(map[string]health.WithHealthInfo, routes.NumRoutes())
|
healthMap := make(map[string]map[string]any, routes.NumRoutes())
|
||||||
routes.RangeRoutes(func(alias string, r route.Route) {
|
routes.RangeRoutes(func(alias string, r route.Route) {
|
||||||
mon := r.HealthMonitor()
|
healthMap[alias] = getHealthInfoRaw(r)
|
||||||
if mon != nil {
|
|
||||||
healthMap[alias] = mon
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
return healthMap
|
return healthMap
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue