Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
......@@ -292,7 +292,7 @@ func main() {
metricsFile = os.Stdout
}
metricsLogger := log.New(metricsFile, "", log.LstdFlags|log.LUTC)
metricsLogger := log.New(metricsFile, "", 0)
ctx := NewBrokerContext(metricsLogger)
......
......@@ -14,7 +14,7 @@ var (
once sync.Once
)
const metricsResolution = 24 * time.Hour
const metricsResolution = 86400 * time.Second
type CountryStats struct {
counts map[string]int
......@@ -34,7 +34,11 @@ type Metrics struct {
}
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) {
......@@ -111,11 +115,11 @@ func (m *Metrics) logMetrics() {
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 ", binCount(m.proxyIdleCount))
m.logger.Println("client-denied-count ", binCount(m.clientDeniedCount))
m.logger.Println("client-snowflake-match-count ", binCount(m.clientProxyMatchCount))
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-idle-count", binCount(m.proxyIdleCount))
m.logger.Println("client-denied-count", binCount(m.clientDeniedCount))
m.logger.Println("client-snowflake-match-count", binCount(m.clientProxyMatchCount))
//restore all metrics to original values
m.proxyIdleCount = 0
......
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