-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstats.go
74 lines (58 loc) · 1.49 KB
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package ipproxy
import (
"context"
"sync/atomic"
"time"
)
func (p *proxy) trackStats(ctx context.Context) {
ticker := time.NewTicker(p.opts.StatsInterval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
log.Debugf("TCP Origins: %v TCP Clients: %v UDP Conns: %v", p.NumTCPOrigins(), p.NumTCPConns(), p.NumUDPConns())
log.Debugf("Accepted Packets: %d Rejected Packets: %d", p.AcceptedPackets(), p.RejectedPackets())
}
}
}
func (p *proxy) acceptedPacket() {
atomic.AddInt64(&p.acceptedPackets, 1)
}
func (p *proxy) AcceptedPackets() int {
return int(atomic.LoadInt64(&p.acceptedPackets))
}
func (p *proxy) rejectedPacket() {
atomic.AddInt64(&p.rejectedPackets, 1)
}
func (p *proxy) RejectedPackets() int {
return int(atomic.LoadInt64(&p.rejectedPackets))
}
func (p *proxy) addTCPOrigin() {
atomic.AddInt64(&p.numTcpOrigins, 1)
}
func (p *proxy) removeTCPOrigin() {
atomic.AddInt64(&p.numTcpOrigins, -1)
}
func (p *proxy) NumTCPOrigins() int {
return int(atomic.LoadInt64(&p.numTcpOrigins))
}
func (p *proxy) addTCPConn() {
atomic.AddInt64(&p.numTcpConns, 1)
}
func (p *proxy) removeTCPConn() {
atomic.AddInt64(&p.numTcpConns, -1)
}
func (p *proxy) NumTCPConns() int {
return int(atomic.LoadInt64(&p.numTcpConns))
}
func (p *proxy) addUDPConn() {
atomic.AddInt64(&p.numUdpConns, 1)
}
func (p *proxy) removeUDPConn() {
atomic.AddInt64(&p.numUdpConns, -1)
}
func (p *proxy) NumUDPConns() int {
return int(atomic.LoadInt64(&p.numUdpConns))
}