-
Notifications
You must be signed in to change notification settings - Fork 6
/
stats.go
74 lines (61 loc) · 1.84 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 prox5
import (
"sync/atomic"
"time"
)
// Statistics is used to encapsulate various proxy engine stats
type Statistics struct {
// Valid4 is the amount of SOCKS4 proxies validated
Valid4 *atomic.Int64
// Valid4a is the amount of SOCKS4a proxies validated
Valid4a *atomic.Int64
// Valid5 is the amount of SOCKS5 proxies validated
Valid5 *atomic.Int64
// ValidHTTP is the amount of HTTP proxies validated
ValidHTTP *atomic.Int64
// Dispensed is a simple ticker to keep track of proxies dispensed via our getters
Dispensed *atomic.Int64
// Stale is the amount of proxies that failed our stale policy upon dispensing
Stale *atomic.Int64
// Checked is the amount of proxies we've checked.
Checked *atomic.Int64
// birthday represents the time we started checking proxies with this pool
birthday *atomic.Pointer[time.Time]
badAccounted *atomic.Int64
accountingLastDone *atomic.Pointer[time.Time]
}
func (stats *Statistics) dispense() {
stats.Dispensed.Add(1)
}
func (stats *Statistics) stale() {
stats.Stale.Add(1)
}
func (stats *Statistics) v4() {
stats.Valid4.Add(1)
}
func (stats *Statistics) v4a() {
stats.Valid4a.Add(1)
}
func (stats *Statistics) v5() {
stats.Valid5.Add(1)
}
func (stats *Statistics) http() {
stats.ValidHTTP.Add(1)
}
// GetTotalValidated retrieves our grand total validated proxy count.
func (p5 *ProxyEngine) GetTotalValidated() int64 {
stats := p5.GetStatistics()
total := int64(0)
for _, val := range []*atomic.Int64{stats.Valid4a, stats.Valid4, stats.Valid5, stats.ValidHTTP} {
total += val.Load()
}
return total
}
func (p5 *ProxyEngine) GetTotalBad() int64 {
p5.badProx.Patrons.DeleteExpired()
return int64(p5.badProx.Patrons.ItemCount())
}
// GetUptime returns the total lifetime duration of our pool.
func (stats *Statistics) GetUptime() time.Duration {
return time.Since(*stats.birthday.Load())
}