prox5/stats.go

70 lines
1.8 KiB
Go
Raw Normal View History

2022-05-23 01:05:50 +00:00
package prox5
import (
"sync/atomic"
"time"
)
2022-10-16 10:53:04 +00:00
// Statistics is used to encapsulate various proxy engine stats
2022-10-16 07:38:49 +00:00
type Statistics struct {
// Valid4 is the amount of SOCKS4 proxies validated
Valid4 int64
// Valid4a is the amount of SOCKS4a proxies validated
Valid4a int64
// Valid5 is the amount of SOCKS5 proxies validated
Valid5 int64
// ValidHTTP is the amount of HTTP proxies validated
ValidHTTP int64
// Dispensed is a simple ticker to keep track of proxies dispensed via our getters
Dispensed int64
// Stale is the amount of proxies that failed our stale policy upon dispensing
Stale int64
// Checked is the amount of proxies we've checked.
Checked int64
2021-09-14 02:47:16 +00:00
// birthday represents the time we started checking proxies with this pool
birthday time.Time
2022-12-27 15:25:10 +00:00
2023-01-31 09:21:29 +00:00
badAccounted int64
accountingLastDone time.Time
}
2022-10-16 07:38:49 +00:00
func (stats *Statistics) dispense() {
atomic.AddInt64(&stats.Dispensed, 1)
}
2022-10-16 07:38:49 +00:00
func (stats *Statistics) stale() {
atomic.AddInt64(&stats.Stale, 1)
}
2022-10-16 07:38:49 +00:00
func (stats *Statistics) v4() {
atomic.AddInt64(&stats.Valid4, 1)
}
2022-10-16 07:38:49 +00:00
func (stats *Statistics) v4a() {
atomic.AddInt64(&stats.Valid4a, 1)
}
2022-10-16 07:38:49 +00:00
func (stats *Statistics) v5() {
atomic.AddInt64(&stats.Valid5, 1)
}
2022-10-16 07:38:49 +00:00
func (stats *Statistics) http() {
atomic.AddInt64(&stats.ValidHTTP, 1)
}
2021-11-25 08:21:41 +00:00
// GetTotalValidated retrieves our grand total validated proxy count.
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) GetTotalValidated() int {
2022-09-22 23:48:08 +00:00
stats := p5.GetStatistics()
return int(atomic.LoadInt64(&stats.Valid4a) + stats.Valid4 + stats.Valid5 + stats.ValidHTTP)
}
2022-12-27 15:25:10 +00:00
func (p5 *ProxyEngine) GetTotalBad() int64 {
2023-01-01 00:40:32 +00:00
p5.badProx.Patrons.DeleteExpired()
2022-12-27 15:25:10 +00:00
return int64(p5.badProx.Patrons.ItemCount())
2021-11-25 08:21:41 +00:00
}
// GetUptime returns the total lifetime duration of our pool.
2022-10-16 07:38:49 +00:00
func (stats *Statistics) GetUptime() time.Duration {
2021-09-14 02:47:16 +00:00
return time.Since(stats.birthday)
}