mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
feat: add option to expose the stats by using metrics
This commit is contained in:
parent
af73ab7d1f
commit
d932cb2744
3 changed files with 124 additions and 2 deletions
29
proxy/lib/pt_event_metrics.go
Normal file
29
proxy/lib/pt_event_metrics.go
Normal 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()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue