Skip to content
Snippets Groups Projects
Commit 25f059f4 authored by Cecylia Bocovich's avatar Cecylia Bocovich
Browse files

Log geoip stats of proxies by unique IP

Change it so that we log the geoip country code of proxies if they poll
within the current metrics epoch. We make sure we log by unique IP
address
parent c782ebdc
No related branches found
No related tags found
No related merge requests found
......@@ -149,6 +149,15 @@ func proxyPolls(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
return
}
log.Println("Received snowflake: ", id)
// Log geoip stats
remoteIP, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
log.Println("Error processing proxy IP: ", err.Error())
} else {
ctx.metrics.UpdateCountryStats(remoteIP)
}
// Wait for a client to avail an offer to the snowflake, or timeout if nil.
offer := ctx.RequestOffer(id)
if nil == offer {
......@@ -224,15 +233,6 @@ func proxyAnswers(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
return
}
// Get proxy country stats
remoteIP, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
log.Println("Error processing proxy IP: ", err.Error())
} else {
ctx.metrics.UpdateCountryStats(remoteIP)
}
log.Println("Received answer.")
snowflake.answerChannel <- body
}
......
......@@ -17,6 +17,7 @@ var (
const metricsResolution = 86400 * time.Second
type CountryStats struct {
ips map[string]bool
counts map[string]int
}
......@@ -65,8 +66,11 @@ func (m *Metrics) UpdateCountryStats(addr string) {
log.Println("Unknown geoip")
}
//update map of countries and counts
m.countryStats.counts[country]++
//update map of unique ips and counts
if !m.countryStats.ips[addr] {
m.countryStats.counts[country]++
m.countryStats.ips[addr] = true
}
return
}
......@@ -101,6 +105,7 @@ func NewMetrics(metricsLogger *log.Logger) (*Metrics, error) {
m.countryStats = CountryStats{
counts: make(map[string]int),
ips: make(map[string]bool),
}
m.logger = metricsLogger
......@@ -126,6 +131,7 @@ func (m *Metrics) logMetrics() {
m.clientDeniedCount = 0
m.clientProxyMatchCount = 0
m.countryStats.counts = make(map[string]int)
m.countryStats.ips = make(map[string]bool)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment