diff options
author | Shelikhoo <xiaokangwang@outlook.com> | 2022-05-27 16:21:28 +0100 |
---|---|---|
committer | Shelikhoo <xiaokangwang@outlook.com> | 2022-06-16 14:58:12 +0100 |
commit | fa7d1e2bb77b92452785ce3d03c81a90efc9891e (patch) | |
tree | a1b1bbfd68eda74831d42a4c8a9e75a0720c4683 /broker | |
parent | 211254fa9849a1ae705a482ba984d0d415730560 (diff) | |
download | snowflake-fa7d1e2bb77b92452785ce3d03c81a90efc9891e.tar.gz snowflake-fa7d1e2bb77b92452785ce3d03c81a90efc9891e.zip |
Add distinct IP counter to metrics
Diffstat (limited to 'broker')
-rw-r--r-- | broker/metrics.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/broker/metrics.go b/broker/metrics.go index 639d505..cd1ca37 100644 --- a/broker/metrics.go +++ b/broker/metrics.go @@ -14,6 +14,7 @@ import ( "sync" "time" + "git.torproject.org/pluggable-transports/snowflake.git/v2/common/ipsetsink/sinkcluster" "git.torproject.org/pluggable-transports/snowflake.git/v2/common/messages" "github.com/prometheus/client_golang/prometheus" "gitlab.torproject.org/tpo/anti-censorship/geoip" @@ -41,6 +42,8 @@ type Metrics struct { logger *log.Logger geoipdb *geoip.Geoip + distinctIPWriter *sinkcluster.ClusterWriter + countryStats CountryStats clientRoundtripEstimate time.Duration proxyIdleCount uint @@ -324,3 +327,13 @@ func initPrometheus() *PromMetrics { return promMetrics } + +func (m *Metrics) RecordIPAddress(ip string) { + if m.distinctIPWriter != nil { + m.distinctIPWriter.AddIPToSet(ip) + } +} + +func (m *Metrics) SetIPAddressRecorder(recorder *sinkcluster.ClusterWriter) { + m.distinctIPWriter = recorder +} |