snowflake/proxy/lib/pt_event_metrics.go
WofWca 583178f4f2
feat(proxy): add failed connection count stats
For the summary log and for Prometheus metrics.

Log output example:

> In the last 1h0m0s, there were 7 completed successful connections. 2 connections failed. Traffic Relayed ↓ 321 KB (0.10 KB/s), ↑ 123 KB (0.05 KB/s).
2025-03-11 13:12:44 +00:00

34 lines
934 B
Go

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(country string)
TrackFailedConnection()
}
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.EventOnProxyStats:
e := e.(event.EventOnProxyStats)
em.collector.TrackInBoundTraffic(e.InboundBytes)
em.collector.TrackOutBoundTraffic(e.OutboundBytes)
case event.EventOnProxyConnectionOver:
e := e.(event.EventOnProxyConnectionOver)
em.collector.TrackNewConnection(e.Country)
case event.EventOnProxyConnectionFailed:
em.collector.TrackFailedConnection()
}
}