Commit d57cd075 authored by Cecylia Bocovich's avatar Cecylia Bocovich
Browse files

Implemented count metrics for broker events

Added three new metrics:
- proxyIdleCount counts the number of times a proxy polls and receives
no snowflakes
- clientDeniedCount counts the number of times a client requested a
snowflake but none were available
- clientProxyMatchCount counts the number of times a client successfully
received a snowflake
parent 64ce7dff
...@@ -153,6 +153,7 @@ func proxyPolls(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) { ...@@ -153,6 +153,7 @@ func proxyPolls(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
offer := ctx.RequestOffer(id) offer := ctx.RequestOffer(id)
if nil == offer { if nil == offer {
log.Println("Proxy " + id + " did not receive a Client offer.") log.Println("Proxy " + id + " did not receive a Client offer.")
ctx.metrics.proxyIdleCount++
w.WriteHeader(http.StatusGatewayTimeout) w.WriteHeader(http.StatusGatewayTimeout)
return return
} }
...@@ -176,6 +177,7 @@ func clientOffers(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) { ...@@ -176,6 +177,7 @@ func clientOffers(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
// Immediately fail if there are no snowflakes available. // Immediately fail if there are no snowflakes available.
if ctx.snowflakes.Len() <= 0 { if ctx.snowflakes.Len() <= 0 {
log.Println("Client: No snowflake proxies available.") log.Println("Client: No snowflake proxies available.")
ctx.metrics.clientDeniedCount++
w.WriteHeader(http.StatusServiceUnavailable) w.WriteHeader(http.StatusServiceUnavailable)
return return
} }
...@@ -189,6 +191,7 @@ func clientOffers(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) { ...@@ -189,6 +191,7 @@ func clientOffers(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
select { select {
case answer := <-snowflake.answerChannel: case answer := <-snowflake.answerChannel:
log.Println("Client: Retrieving answer") log.Println("Client: Retrieving answer")
ctx.metrics.clientProxyMatchCount++
w.Write(answer) w.Write(answer)
// Initial tracking of elapsed time. // Initial tracking of elapsed time.
ctx.metrics.clientRoundtripEstimate = time.Since(startTime) / ctx.metrics.clientRoundtripEstimate = time.Since(startTime) /
......
...@@ -21,11 +21,15 @@ type CountryStats struct { ...@@ -21,11 +21,15 @@ type CountryStats struct {
// Implements Observable // Implements Observable
type Metrics struct { type Metrics struct {
tablev4 *GeoIPv4Table logger *log.Logger
tablev6 *GeoIPv6Table tablev4 *GeoIPv4Table
countryStats CountryStats tablev6 *GeoIPv6Table
// snowflakes timeseries.Float
countryStats CountryStats
clientRoundtripEstimate time.Duration clientRoundtripEstimate time.Duration
proxyIdleCount int
clientDeniedCount int
clientProxyMatchCount int
} }
func (s CountryStats) Display() string { func (s CountryStats) Display() string {
...@@ -94,17 +98,25 @@ func NewMetrics(metricsLogger *log.Logger) (*Metrics, error) { ...@@ -94,17 +98,25 @@ func NewMetrics(metricsLogger *log.Logger) (*Metrics, error) {
counts: make(map[string]int), counts: make(map[string]int),
} }
m.logger = metricsLogger
// Write to log file every hour with updated metrics // Write to log file every hour with updated metrics
go once.Do(func() { go once.Do(m.logMetrics)
heartbeat := time.Tick(metricsResolution)
for range heartbeat { return m, nil
metricsLogger.Println("Country stats: ", m.countryStats.Display()) }
//restore all metrics to original values func (m *Metrics) logMetrics() {
m.countryStats.counts = make(map[string]int)
} heartbeat := time.Tick(metricsResolution)
}) for range heartbeat {
m.logger.Println("snowflake-stats-end ")
m.logger.Println("snowflake-ips ", m.countryStats.Display())
m.logger.Println("snowflake-idle-count ", m.proxyIdleCount)
m.logger.Println("client-denied-count ", m.clientDeniedCount)
m.logger.Println("client-snowflake-match-count ", m.clientProxyMatchCount)
return m, nil //restore all metrics to original values
m.countryStats.counts = make(map[string]int)
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment