mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
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:
parent
175b8efb04
commit
c782ebdcea
2 changed files with 12 additions and 8 deletions
|
@ -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 (
|
||||||
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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue