mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
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).
This commit is contained in:
parent
5ef4761968
commit
583178f4f2
5 changed files with 53 additions and 13 deletions
|
@ -42,11 +42,14 @@ func (p *proxyEventLogger) OnNewSnowflakeEvent(e event.SnowflakeEvent) {
|
|||
}
|
||||
|
||||
type periodicProxyStats struct {
|
||||
bytesLogger bytesLogger
|
||||
bytesLogger bytesLogger
|
||||
// Completed successful connections.
|
||||
connectionCount int
|
||||
logPeriod time.Duration
|
||||
task *task.Periodic
|
||||
dispatcher event.SnowflakeEventDispatcher
|
||||
// Connections that failed to establish.
|
||||
failedConnectionCount uint
|
||||
logPeriod time.Duration
|
||||
task *task.Periodic
|
||||
dispatcher event.SnowflakeEventDispatcher
|
||||
}
|
||||
|
||||
func newPeriodicProxyStats(logPeriod time.Duration, dispatcher event.SnowflakeEventDispatcher, bytesLogger bytesLogger) *periodicProxyStats {
|
||||
|
@ -60,19 +63,23 @@ func (p *periodicProxyStats) OnNewSnowflakeEvent(e event.SnowflakeEvent) {
|
|||
switch e.(type) {
|
||||
case event.EventOnProxyConnectionOver:
|
||||
p.connectionCount += 1
|
||||
case event.EventOnProxyConnectionFailed:
|
||||
p.failedConnectionCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
func (p *periodicProxyStats) logTick() error {
|
||||
inboundSum, outboundSum := p.bytesLogger.GetStat()
|
||||
e := event.EventOnProxyStats{
|
||||
SummaryInterval: p.logPeriod,
|
||||
ConnectionCount: p.connectionCount,
|
||||
SummaryInterval: p.logPeriod,
|
||||
ConnectionCount: p.connectionCount,
|
||||
FailedConnectionCount: p.failedConnectionCount,
|
||||
}
|
||||
e.InboundBytes, e.InboundUnit = formatTraffic(inboundSum)
|
||||
e.OutboundBytes, e.OutboundUnit = formatTraffic(outboundSum)
|
||||
p.dispatcher.OnNewSnowflakeEvent(e)
|
||||
p.connectionCount = 0
|
||||
p.failedConnectionCount = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue