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.
This commit is contained in:
Cecylia Bocovich 2019-06-11 15:01:05 -04:00
parent 175b8efb04
commit c782ebdcea
2 changed files with 12 additions and 8 deletions

View file

@ -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)

View file

@ -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,7 +115,7 @@ func (m *Metrics) logMetrics() {
heartbeat := time.Tick(metricsResolution)
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-idle-count", binCount(m.proxyIdleCount))
m.logger.Println("client-denied-count", binCount(m.clientDeniedCount))