Add proxy type to stats exported by broker

This commit is contained in:
Cecylia Bocovich 2019-11-20 13:27:04 -05:00
parent 8ab81fc6cd
commit 981abffbd9
3 changed files with 111 additions and 22 deletions

View file

@ -19,6 +19,24 @@ We export metrics in the following format:
A count of the total number of unique IP addresses of snowflake
proxies that have polled.
"snowflake-ips-standalone" NUM NL
[At most once.]
A count of the total number of unique IP addresses of snowflake
proxies of type "standalone" that have polled.
"snowflake-ips-badge" NUM NL
[At most once.]
A count of the total number of unique IP addresses of snowflake
proxies of type "badge" that have polled.
"snowflake-ips-webext" NUM NL
[At most once.]
A count of the total number of unique IP addresses of snowflake
proxies of type "webext" that have polled.
"snowflake-idle-count" NUM NL
[At most once.]
@ -58,8 +76,11 @@ var (
const metricsResolution = 60 * 60 * 24 * time.Second //86400 seconds
type CountryStats struct {
addrs map[string]bool
counts map[string]int
standalone map[string]bool
badge map[string]bool
webext map[string]bool
unknown map[string]bool
counts map[string]int
}
// Implements Observable
@ -89,13 +110,27 @@ func (s CountryStats) Display() string {
return output
}
func (m *Metrics) UpdateCountryStats(addr string) {
func (m *Metrics) UpdateCountryStats(addr string, ptype string) {
var country string
var ok bool
if m.countryStats.addrs[addr] {
return
if ptype == "standalone" {
if m.countryStats.standalone[addr] {
return
}
} else if ptype == "badge" {
if m.countryStats.badge[addr] {
return
}
} else if ptype == "webext" {
if m.countryStats.webext[addr] {
return
}
} else {
if m.countryStats.unknown[addr] {
return
}
}
ip := net.ParseIP(addr)
@ -118,7 +153,15 @@ func (m *Metrics) UpdateCountryStats(addr string) {
//update map of unique ips and counts
m.countryStats.counts[country]++
m.countryStats.addrs[addr] = true
if ptype == "standalone" {
m.countryStats.standalone[addr] = true
} else if ptype == "badge" {
m.countryStats.badge[addr] = true
} else if ptype == "webext" {
m.countryStats.webext[addr] = true
} else {
m.countryStats.unknown[addr] = true
}
}
@ -148,8 +191,11 @@ func NewMetrics(metricsLogger *log.Logger) (*Metrics, error) {
m := new(Metrics)
m.countryStats = CountryStats{
counts: make(map[string]int),
addrs: make(map[string]bool),
counts: make(map[string]int),
standalone: make(map[string]bool),
badge: make(map[string]bool),
webext: make(map[string]bool),
unknown: make(map[string]bool),
}
m.logger = metricsLogger
@ -172,7 +218,11 @@ func (m *Metrics) logMetrics() {
func (m *Metrics) printMetrics() {
m.logger.Println("snowflake-stats-end", time.Now().UTC().Format("2006-01-02 15:04:05"), fmt.Sprintf("(%d s)", int(metricsResolution.Seconds())))
m.logger.Println("snowflake-ips", m.countryStats.Display())
m.logger.Println("snowflake-ips-total", len(m.countryStats.addrs))
m.logger.Println("snowflake-ips-total", len(m.countryStats.standalone)+
len(m.countryStats.badge)+len(m.countryStats.webext)+len(m.countryStats.unknown))
m.logger.Println("snowflake-ips-standalone", len(m.countryStats.standalone))
m.logger.Println("snowflake-ips-badge", len(m.countryStats.badge))
m.logger.Println("snowflake-ips-webext", len(m.countryStats.webext))
m.logger.Println("snowflake-idle-count", binCount(m.proxyIdleCount))
m.logger.Println("client-denied-count", binCount(m.clientDeniedCount))
m.logger.Println("client-snowflake-match-count", binCount(m.clientProxyMatchCount))
@ -184,7 +234,10 @@ func (m *Metrics) zeroMetrics() {
m.clientDeniedCount = 0
m.clientProxyMatchCount = 0
m.countryStats.counts = make(map[string]int)
m.countryStats.addrs = make(map[string]bool)
m.countryStats.standalone = make(map[string]bool)
m.countryStats.badge = make(map[string]bool)
m.countryStats.webext = make(map[string]bool)
m.countryStats.unknown = make(map[string]bool)
}
// Rounds up a count to the nearest multiple of 8.