prox5/stats.go

62 lines
1.4 KiB
Go
Raw Normal View History

2022-05-23 01:05:50 +00:00
package prox5
import (
"sync"
"time"
)
// Statistics is used to encapsulate various swampy stats
type Statistics struct {
// Valid4 is the amount of SOCKS4 proxies validated
Valid4 int
// Valid4a is the amount of SOCKS4a proxies validated
Valid4a int
// Valid5 is the amount of SOCKS5 proxies validated
Valid5 int
// ValidHTTP is the amount of HTTP proxies validated
ValidHTTP int
// Dispensed is a simple ticker to keep track of proxies dispensed via our getters
Dispensed int
// Stale is the amount of proxies that failed our stale policy upon dispensing
Stale int
// Checked is the amount of proxies we've checked.
Checked int
2021-09-14 02:47:16 +00:00
// birthday represents the time we started checking proxies with this pool
birthday time.Time
2021-09-21 12:24:30 +00:00
mu *sync.Mutex
}
func (stats *Statistics) dispense() {
stats.Dispensed++
}
func (stats *Statistics) stale() {
stats.Stale++
}
func (stats *Statistics) v4() {
stats.Valid4++
}
func (stats *Statistics) v4a() {
stats.Valid4a++
}
func (stats *Statistics) v5() {
stats.Valid5++
}
func (stats *Statistics) http() {
stats.ValidHTTP++
}
2021-11-25 08:21:41 +00:00
// GetTotalValidated retrieves our grand total validated proxy count.
2022-05-30 10:42:18 +00:00
func (s *Swamp) GetTotalValidated() int {
return s.Stats.Valid4a + s.Stats.Valid4 + s.Stats.Valid5 + s.Stats.ValidHTTP
2021-11-25 08:21:41 +00:00
}
// GetUptime returns the total lifetime duration of our pool.
func (stats *Statistics) GetUptime() time.Duration {
2021-09-14 02:47:16 +00:00
return time.Since(stats.birthday)
}