Modify EventOnProxyStats to include summary data

This commit is contained in:
Cecylia Bocovich 2023-10-30 12:37:56 -04:00
parent 018bbd6d65
commit 5c5eb2c339
No known key found for this signature in database
GPG key ID: 009DE379FD9B7B90
2 changed files with 15 additions and 8 deletions

View file

@ -1,7 +1,6 @@
package snowflake_proxy
import (
"fmt"
"io"
"log"
"time"
@ -47,11 +46,13 @@ func (p *periodicProxyStats) OnNewSnowflakeEvent(e event.SnowflakeEvent) {
func (p *periodicProxyStats) logTick() error {
inboundSum, outboundSum := p.bytesLogger.GetStat()
inbound, inboundUnit := formatTraffic(inboundSum)
outbound, outboundUnit := formatTraffic(outboundSum)
statString := fmt.Sprintf("In the last %v, there were %v completed connections. Traffic Relayed ↓ %v %v, ↑ %v %v.",
p.logPeriod.String(), p.connectionCount, inbound, inboundUnit, outbound, outboundUnit)
p.dispatcher.OnNewSnowflakeEvent(&event.EventOnProxyStats{StatString: statString})
e := &event.EventOnProxyStats{
SummaryInterval: p.logPeriod,
ConnectionCount: p.connectionCount,
}
e.InboundBytes, e.InboundUnit = formatTraffic(inboundSum)
e.OutboundBytes, e.OutboundUnit = formatTraffic(outboundSum)
p.dispatcher.OnNewSnowflakeEvent(e)
p.connectionCount = 0
return nil
}