feat(go): track gateway active connections
This commit is contained in:
@@ -145,6 +145,8 @@ func (s *TCPServer) handleConnection(ctx context.Context, conn net.Conn) {
|
||||
defer conn.Close()
|
||||
source := conn.RemoteAddr().String()
|
||||
log := s.logger.With("protocol", s.protocol.Protocol, "remote", source)
|
||||
s.recordConnectionMetric(1)
|
||||
defer s.recordConnectionMetric(-1)
|
||||
log.Info("tcp connection opened")
|
||||
defer log.Info("tcp connection closed")
|
||||
|
||||
@@ -268,6 +270,15 @@ func (s *TCPServer) recordPublishMetric(kind string, status string) {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *TCPServer) recordConnectionMetric(delta float64) {
|
||||
if s.metrics == nil {
|
||||
return
|
||||
}
|
||||
s.metrics.AddGauge("vehicle_gateway_active_connections", metrics.Labels{
|
||||
"protocol": string(s.protocol.Protocol),
|
||||
}, delta)
|
||||
}
|
||||
|
||||
func (p TCPProtocol) String() string {
|
||||
return fmt.Sprintf("%s@%s", p.Protocol, p.Addr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user