mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-21 07:51:28 +02:00
fix: uptime metrics
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/yusing/go-proxy/internal/homepage"
|
||||
@@ -29,6 +30,27 @@ type HealthInfoRaw struct {
|
||||
Latency time.Duration `json:"latency"`
|
||||
}
|
||||
|
||||
func (info *HealthInfoRaw) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(map[string]any{
|
||||
"status": info.Status.String(),
|
||||
"latency": info.Latency.Milliseconds(),
|
||||
})
|
||||
}
|
||||
|
||||
func (info *HealthInfoRaw) UnmarshalJSON(data []byte) error {
|
||||
var v map[string]any
|
||||
if err := json.Unmarshal(data, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
if status, ok := v["status"].(string); ok {
|
||||
info.Status = health.NewStatus(status)
|
||||
}
|
||||
if latency, ok := v["latency"].(float64); ok {
|
||||
info.Latency = time.Duration(latency)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getHealthInfoRaw(r Route) *HealthInfoRaw {
|
||||
mon := r.HealthMonitor()
|
||||
if mon == nil {
|
||||
|
||||
Reference in New Issue
Block a user