initial prometheus metrics support, simplfied some code

This commit is contained in:
yusing
2024-11-06 12:24:12 +08:00
parent 50a0686648
commit 6712e9b109
23 changed files with 383 additions and 125 deletions

View File

@@ -10,7 +10,6 @@ import (
U "github.com/yusing/go-proxy/internal/api/v1/utils"
"github.com/yusing/go-proxy/internal/common"
"github.com/yusing/go-proxy/internal/config"
"github.com/yusing/go-proxy/internal/server"
"github.com/yusing/go-proxy/internal/utils/strutils"
)
@@ -33,7 +32,6 @@ func StatsWS(w http.ResponseWriter, r *http.Request) {
}
originPats = append(originPats, localAddresses...)
}
U.LogInfo(r).Msgf("websocket API request from origins: %s", originPats)
if common.IsDebug {
originPats = []string{"*"}
}
@@ -62,9 +60,11 @@ func StatsWS(w http.ResponseWriter, r *http.Request) {
}
}
var startTime = time.Now()
func getStats() map[string]any {
return map[string]any{
"proxies": config.Statistics(),
"uptime": strutils.FormatDuration(server.GetProxyServer().Uptime()),
"uptime": strutils.FormatDuration(time.Since(startTime)),
}
}