[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/master] Format output to meet specification



commit c782ebdcea30aa0156921939ee99299381245cd7
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date:   Tue Jun 11 15:01:05 2019 -0400

    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.
---
 broker/broker.go  |  2 +-
 broker/metrics.go | 18 +++++++++++-------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/broker/broker.go b/broker/broker.go
index 971e3ad..3795f2b 100644
--- a/broker/broker.go
+++ b/broker/broker.go
@@ -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)
 
diff --git a/broker/metrics.go b/broker/metrics.go
index 2c798ee..a7f077a 100644
--- a/broker/metrics.go
+++ b/broker/metrics.go
@@ -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



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits