recorder: add input/output traffic stats for handler recorder object

This commit is contained in:
ginuerzh
2024-10-11 20:32:56 +08:00
parent 8f994ab632
commit 27242d0b66
15 changed files with 169 additions and 62 deletions
+9 -2
View File
@@ -112,14 +112,21 @@ func (h *socks4Handler) Handle(ctx context.Context, conn net.Conn, opts ...handl
"local": conn.LocalAddr().String(),
"sid": ctxvalue.SidFromContext(ctx),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
pStats := stats.Stats{}
conn = stats_wrapper.WrapConn(conn, &pStats)
defer func() {
if err != nil {
ro.Err = err.Error()
}
ro.InputBytes = pStats.Get(stats.KindInputBytes)
ro.OutputBytes = pStats.Get(stats.KindOutputBytes)
ro.Duration = time.Since(start)
ro.Record(ctx, h.recorder.Recorder)
if err := ro.Record(ctx, h.recorder.Recorder); err != nil {
log.Errorf("record: %v", err)
}
log.WithFields(map[string]any{
"duration": time.Since(start),