feat: add option to expose the stats by using metrics

This commit is contained in:
am3o 2023-03-21 16:46:38 +01:00 committed by Shelikhoo
parent af73ab7d1f
commit d932cb2744
No known key found for this signature in database
GPG key ID: C4D5E79D22B25316
3 changed files with 124 additions and 2 deletions

View file

@ -0,0 +1,29 @@
package snowflake_proxy
import (
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/event"
)
type EventCollector interface {
TrackInBoundTraffic(value int64)
TrackOutBoundTraffic(value int64)
TrackNewConnection()
}
type EventMetrics struct {
collector EventCollector
}
func NewEventMetrics(collector EventCollector) *EventMetrics {
return &EventMetrics{collector: collector}
}
func (em *EventMetrics) OnNewSnowflakeEvent(e event.SnowflakeEvent) {
switch e.(type) {
case event.EventOnProxyConnectionOver:
e := e.(event.EventOnProxyConnectionOver)
em.collector.TrackInBoundTraffic(e.InboundTraffic)
em.collector.TrackOutBoundTraffic(e.OutboundTraffic)
em.collector.TrackNewConnection()
}
}