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

Format output to meet specification

Output is now printed out in Tor Directory Protocol Format, as specified
in https://trac.torproject.org/projects/tor/ticket/21315#comment:19.
parent 175b8efb
...@@ -292,7 +292,7 @@ func main() { ...@@ -292,7 +292,7 @@ func main() {
metricsFile = os.Stdout metricsFile = os.Stdout
} }
metricsLogger := log.New(metricsFile, "", log.LstdFlags|log.LUTC) metricsLogger := log.New(metricsFile, "", 0)
ctx := NewBrokerContext(metricsLogger) ctx := NewBrokerContext(metricsLogger)
......
...@@ -14,7 +14,7 @@ var ( ...@@ -14,7 +14,7 @@ var (
once sync.Once once sync.Once
) )
const metricsResolution = 24 * time.Hour const metricsResolution = 86400 * time.Second
type CountryStats struct { type CountryStats struct {
counts map[string]int counts map[string]int
...@@ -34,7 +34,11 @@ type Metrics struct { ...@@ -34,7 +34,11 @@ type Metrics struct {
} }
func (s CountryStats) Display() string { func (s CountryStats) Display() string {
return fmt.Sprint(s.counts) output := ""
for cc, count := range s.counts {
output += fmt.Sprintf("%s=%d,", cc, count)
}
return output
} }
func (m *Metrics) UpdateCountryStats(addr string) { func (m *Metrics) UpdateCountryStats(addr string) {
...@@ -111,11 +115,11 @@ func (m *Metrics) logMetrics() { ...@@ -111,11 +115,11 @@ func (m *Metrics) logMetrics() {
heartbeat := time.Tick(metricsResolution) heartbeat := time.Tick(metricsResolution)
for range heartbeat { for range heartbeat {
m.logger.Println("snowflake-stats-end ") m.logger.Println("snowflake-stats-end", time.Now().UTC().Format("2006-01-02 15:04:05"), "(", int(metricsResolution.Seconds()), "s)")
m.logger.Println("snowflake-ips ", m.countryStats.Display()) m.logger.Println("snowflake-ips", m.countryStats.Display())
m.logger.Println("snowflake-idle-count ", binCount(m.proxyIdleCount)) m.logger.Println("snowflake-idle-count", binCount(m.proxyIdleCount))
m.logger.Println("client-denied-count ", binCount(m.clientDeniedCount)) m.logger.Println("client-denied-count", binCount(m.clientDeniedCount))
m.logger.Println("client-snowflake-match-count ", binCount(m.clientProxyMatchCount)) m.logger.Println("client-snowflake-match-count", binCount(m.clientProxyMatchCount))
//restore all metrics to original values //restore all metrics to original values
m.proxyIdleCount = 0 m.proxyIdleCount = 0
......
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