uptime metrics

This commit is contained in:
yusing
2024-11-07 11:44:01 +08:00
parent 6be3aef367
commit 5214ae1760
2 changed files with 39 additions and 2 deletions

View File

@@ -7,8 +7,10 @@ import (
"strings"
"time"
"github.com/yusing/go-proxy/internal/common"
E "github.com/yusing/go-proxy/internal/error"
"github.com/yusing/go-proxy/internal/logging"
"github.com/yusing/go-proxy/internal/metrics"
"github.com/yusing/go-proxy/internal/net/types"
"github.com/yusing/go-proxy/internal/notif"
"github.com/yusing/go-proxy/internal/task"
@@ -172,6 +174,16 @@ func (mon *monitor) checkUpdateHealth() error {
logger.Debug().Msg(detail)
notif.Notify(mon.service, "server is down")
}
if common.PrometheusEnabled {
go func() {
m := metrics.GetRouteMetrics()
var up float64
if healthy {
up = 1
}
m.HealthStatus.With(metrics.HealthMetricLabels(mon.service)).Set(up)
}()
}
}
return nil