prox5/stats.go

61 lines
1.4 KiB
Go
Raw Normal View History

2022-05-23 01:05:50 +00:00
package prox5
import (
"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-10-16 07:38:49 +00:00
func (stats *Statistics) dispense() {
stats.Dispensed++
}
2022-10-16 07:38:49 +00:00
func (stats *Statistics) stale() {
stats.Stale++
}
2022-10-16 07:38:49 +00:00
func (stats *Statistics) v4() {
stats.Valid4++
}
2022-10-16 07:38:49 +00:00
func (stats *Statistics) v4a() {
stats.Valid4a++
}
2022-10-16 07:38:49 +00:00
func (stats *Statistics) v5() {
stats.Valid5++
}
2022-10-16 07:38:49 +00:00
func (stats *Statistics) http() {
stats.ValidHTTP++
}
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()
2022-06-26 02:51:42 +00:00
return int(stats.Valid4a + stats.Valid4 + stats.Valid5 + stats.ValidHTTP)
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)
}