添加在线调试 api

This commit is contained in:
2025-03-08 10:59:31 +08:00
parent 053041ae34
commit 5786ac9d99
28 changed files with 236 additions and 539 deletions

View File

@@ -5,9 +5,12 @@ import (
"log/slog"
"net"
"proxy-server/pkg/utils"
"proxy-server/server/debug"
"proxy-server/server/fwd/metrics"
"proxy-server/server/pkg/env"
"strconv"
"sync"
"time"
"github.com/pkg/errors"
)
@@ -77,6 +80,7 @@ func (s *Service) processDataConn(client net.Conn) error {
return errors.New("用户连接已关闭tag" + tag)
}
defer utils.Close(user)
data := time.Now()
// 检查状态
if status != 1 {
@@ -116,5 +120,34 @@ func (s *Service) processDataConn(client net.Conn) error {
case <-utils.ChanWgWait(s.ctx, &wg):
}
proxy := time.Now()
start, startOk := metrics.TimerStart.Load(user.Conn)
auth, authOk := metrics.TimerAuth.Load(user.Conn)
var authDuration time.Duration
if startOk && authOk {
authDuration = auth.(time.Time).Sub(start.(time.Time))
}
var dataDuration time.Duration
if authOk {
dataDuration = data.Sub(auth.(time.Time))
}
proxyDuration := proxy.Sub(data)
var totalDuration time.Duration
if startOk {
totalDuration = proxy.Sub(start.(time.Time))
}
debug.ConsumingCh <- debug.Consuming{
Auth: authDuration,
Data: dataDuration,
Proxy: proxyDuration,
Total: totalDuration,
}
return nil
}