diff --git a/apidocs/openapi.yaml b/apidocs/openapi.yaml index afdf8c10..68dedbf2 100644 --- a/apidocs/openapi.yaml +++ b/apidocs/openapi.yaml @@ -626,12 +626,6 @@ components: type: string query: type: string - bytesReceived: - type: integer - format: int64 - bytesSent: - type: integer - format: int64 packetsSent: type: integer format: int64 @@ -704,6 +698,14 @@ components: type: integer format: int64 description: The total number of packets that failed to be decrypted at the receiver side + bytesSent: + type: integer + format: int64 + description: Same as packetsSent, but expressed in bytes, including payload and all the headers (IP, TCP, SRT) + bytesReceived: + type: integer + format: int64 + description: Same as packetsReceived, but expressed in bytes, including payload and all the headers (IP, TCP, SRT) bytesSentUnique: type: integer format: int64 diff --git a/internal/defs/api.go b/internal/defs/api.go index 3e1bcb97..7169d464 100644 --- a/internal/defs/api.go +++ b/internal/defs/api.go @@ -155,12 +155,8 @@ type APISRTConn struct { Path string `json:"path"` Query string `json:"query"` - APISRTConnMetrics -} + // The metric names/comments are pulled from GoSRT -// APISRTConnMetrics contains all the extra metrics for the SRT connections -// The metric names/comments are pulled from GoSRT -type APISRTConnMetrics struct { // The total number of sent DATA packets, including retransmitted packets PacketsSent uint64 `json:"packetsSent"` // The total number of received DATA packets, including retransmitted packets diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index e3c0d6e2..4a2520fb 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -233,8 +233,6 @@ func (m *Metrics) onMetrics(ctx *gin.Context) { for _, i := range data.Items { tags := "{id=\"" + i.ID.String() + "\",state=\"" + string(i.State) + "\"}" out += metric("srt_conns", tags, 1) - out += metric("srt_conns_bytes_received", tags, int64(i.BytesReceived)) - out += metric("srt_conns_bytes_sent", tags, int64(i.BytesSent)) out += metric("srt_conns_packets_sent", tags, int64(i.PacketsSent)) out += metric("srt_conns_packets_received", tags, int64(i.PacketsReceived)) out += metric("srt_conns_packets_sent_unique", tags, int64(i.PacketsSentUnique)) @@ -253,6 +251,8 @@ func (m *Metrics) onMetrics(ctx *gin.Context) { out += metric("srt_conns_packets_send_drop", tags, int64(i.PacketsSendDrop)) out += metric("srt_conns_packets_received_drop", tags, int64(i.PacketsReceivedDrop)) out += metric("srt_conns_packets_received_undecrypt", tags, int64(i.PacketsReceivedUndecrypt)) + out += metric("srt_conns_bytes_sent", tags, int64(i.BytesSent)) + out += metric("srt_conns_bytes_received", tags, int64(i.BytesReceived)) out += metric("srt_conns_bytes_sent_unique", tags, int64(i.BytesSentUnique)) out += metric("srt_conns_bytes_received_unique", tags, int64(i.BytesReceivedUnique)) out += metric("srt_conns_bytes_received_loss", tags, int64(i.BytesReceivedLoss)) diff --git a/internal/servers/srt/conn.go b/internal/servers/srt/conn.go index 845f4163..094ebc4a 100644 --- a/internal/servers/srt/conn.go +++ b/internal/servers/srt/conn.go @@ -389,67 +389,7 @@ func (c *conn) apiItem() *defs.APISRTConn { c.mutex.RLock() defer c.mutex.RUnlock() - var connMetrics defs.APISRTConnMetrics - if c.sconn != nil { - var s srt.Statistics - c.sconn.Stats(&s) - - connMetrics.PacketsSent = s.Accumulated.PktSent - connMetrics.PacketsReceived = s.Accumulated.PktRecv - connMetrics.PacketsSentUnique = s.Accumulated.PktSentUnique - connMetrics.PacketsReceivedUnique = s.Accumulated.PktRecvUnique - connMetrics.PacketsSendLoss = s.Accumulated.PktSendLoss - connMetrics.PacketsReceivedLoss = s.Accumulated.PktRecvLoss - connMetrics.PacketsRetrans = s.Accumulated.PktRetrans - connMetrics.PacketsReceivedRetrans = s.Accumulated.PktRecvRetrans - connMetrics.PacketsSentACK = s.Accumulated.PktSentACK - connMetrics.PacketsReceivedACK = s.Accumulated.PktRecvACK - connMetrics.PacketsSentNAK = s.Accumulated.PktSentNAK - connMetrics.PacketsReceivedNAK = s.Accumulated.PktRecvNAK - connMetrics.PacketsSentKM = s.Accumulated.PktSentKM - connMetrics.PacketsReceivedKM = s.Accumulated.PktRecvKM - connMetrics.UsSndDuration = s.Accumulated.UsSndDuration - connMetrics.PacketsReceivedBelated = s.Accumulated.PktRecvBelated - connMetrics.PacketsSendDrop = s.Accumulated.PktSendDrop - connMetrics.PacketsReceivedDrop = s.Accumulated.PktRecvDrop - connMetrics.PacketsReceivedUndecrypt = s.Accumulated.PktRecvUndecrypt - connMetrics.BytesSent = s.Accumulated.ByteSent - connMetrics.BytesReceived = s.Accumulated.ByteRecv - connMetrics.BytesSentUnique = s.Accumulated.ByteSentUnique - connMetrics.BytesReceivedUnique = s.Accumulated.ByteRecvUnique - connMetrics.BytesReceivedLoss = s.Accumulated.ByteRecvLoss - connMetrics.BytesRetrans = s.Accumulated.ByteRetrans - connMetrics.BytesReceivedRetrans = s.Accumulated.ByteRecvRetrans - connMetrics.BytesReceivedBelated = s.Accumulated.ByteRecvBelated - connMetrics.BytesSendDrop = s.Accumulated.ByteSendDrop - connMetrics.BytesReceivedDrop = s.Accumulated.ByteRecvDrop - connMetrics.BytesReceivedUndecrypt = s.Accumulated.ByteRecvUndecrypt - connMetrics.UsPacketsSendPeriod = s.Instantaneous.UsPktSendPeriod - connMetrics.PacketsFlowWindow = s.Instantaneous.PktFlowWindow - connMetrics.PacketsFlightSize = s.Instantaneous.PktFlightSize - connMetrics.MsRTT = s.Instantaneous.MsRTT - connMetrics.MbpsSendRate = s.Instantaneous.MbpsSentRate - connMetrics.MbpsReceiveRate = s.Instantaneous.MbpsRecvRate - connMetrics.MbpsLinkCapacity = s.Instantaneous.MbpsLinkCapacity - connMetrics.BytesAvailSendBuf = s.Instantaneous.ByteAvailSendBuf - connMetrics.BytesAvailReceiveBuf = s.Instantaneous.ByteAvailRecvBuf - connMetrics.MbpsMaxBW = s.Instantaneous.MbpsMaxBW - connMetrics.ByteMSS = s.Instantaneous.ByteMSS - connMetrics.PacketsSendBuf = s.Instantaneous.PktSendBuf - connMetrics.BytesSendBuf = s.Instantaneous.ByteSendBuf - connMetrics.MsSendBuf = s.Instantaneous.MsSendBuf - connMetrics.MsSendTsbPdDelay = s.Instantaneous.MsSendTsbPdDelay - connMetrics.PacketsReceiveBuf = s.Instantaneous.PktRecvBuf - connMetrics.BytesReceiveBuf = s.Instantaneous.ByteRecvBuf - connMetrics.MsReceiveBuf = s.Instantaneous.MsRecvBuf - connMetrics.MsReceiveTsbPdDelay = s.Instantaneous.MsRecvTsbPdDelay - connMetrics.PacketsReorderTolerance = s.Instantaneous.PktReorderTolerance - connMetrics.PacketsReceivedAvgBelatedTime = s.Instantaneous.PktRecvAvgBelatedTime - connMetrics.PacketsSendLossRate = s.Instantaneous.PktSendLossRate - connMetrics.PacketsReceivedLossRate = s.Instantaneous.PktRecvLossRate - } - - return &defs.APISRTConn{ + item := &defs.APISRTConn{ ID: c.uuid, Created: c.created, RemoteAddr: c.connReq.RemoteAddr().String(), @@ -465,8 +405,68 @@ func (c *conn) apiItem() *defs.APISRTConn { return defs.APISRTConnStateIdle } }(), - Path: c.pathName, - Query: c.query, - APISRTConnMetrics: connMetrics, + Path: c.pathName, + Query: c.query, } + + if c.sconn != nil { + var s srt.Statistics + c.sconn.Stats(&s) + + item.PacketsSent = s.Accumulated.PktSent + item.PacketsReceived = s.Accumulated.PktRecv + item.PacketsSentUnique = s.Accumulated.PktSentUnique + item.PacketsReceivedUnique = s.Accumulated.PktRecvUnique + item.PacketsSendLoss = s.Accumulated.PktSendLoss + item.PacketsReceivedLoss = s.Accumulated.PktRecvLoss + item.PacketsRetrans = s.Accumulated.PktRetrans + item.PacketsReceivedRetrans = s.Accumulated.PktRecvRetrans + item.PacketsSentACK = s.Accumulated.PktSentACK + item.PacketsReceivedACK = s.Accumulated.PktRecvACK + item.PacketsSentNAK = s.Accumulated.PktSentNAK + item.PacketsReceivedNAK = s.Accumulated.PktRecvNAK + item.PacketsSentKM = s.Accumulated.PktSentKM + item.PacketsReceivedKM = s.Accumulated.PktRecvKM + item.UsSndDuration = s.Accumulated.UsSndDuration + item.PacketsReceivedBelated = s.Accumulated.PktRecvBelated + item.PacketsSendDrop = s.Accumulated.PktSendDrop + item.PacketsReceivedDrop = s.Accumulated.PktRecvDrop + item.PacketsReceivedUndecrypt = s.Accumulated.PktRecvUndecrypt + item.BytesSent = s.Accumulated.ByteSent + item.BytesReceived = s.Accumulated.ByteRecv + item.BytesSentUnique = s.Accumulated.ByteSentUnique + item.BytesReceivedUnique = s.Accumulated.ByteRecvUnique + item.BytesReceivedLoss = s.Accumulated.ByteRecvLoss + item.BytesRetrans = s.Accumulated.ByteRetrans + item.BytesReceivedRetrans = s.Accumulated.ByteRecvRetrans + item.BytesReceivedBelated = s.Accumulated.ByteRecvBelated + item.BytesSendDrop = s.Accumulated.ByteSendDrop + item.BytesReceivedDrop = s.Accumulated.ByteRecvDrop + item.BytesReceivedUndecrypt = s.Accumulated.ByteRecvUndecrypt + item.UsPacketsSendPeriod = s.Instantaneous.UsPktSendPeriod + item.PacketsFlowWindow = s.Instantaneous.PktFlowWindow + item.PacketsFlightSize = s.Instantaneous.PktFlightSize + item.MsRTT = s.Instantaneous.MsRTT + item.MbpsSendRate = s.Instantaneous.MbpsSentRate + item.MbpsReceiveRate = s.Instantaneous.MbpsRecvRate + item.MbpsLinkCapacity = s.Instantaneous.MbpsLinkCapacity + item.BytesAvailSendBuf = s.Instantaneous.ByteAvailSendBuf + item.BytesAvailReceiveBuf = s.Instantaneous.ByteAvailRecvBuf + item.MbpsMaxBW = s.Instantaneous.MbpsMaxBW + item.ByteMSS = s.Instantaneous.ByteMSS + item.PacketsSendBuf = s.Instantaneous.PktSendBuf + item.BytesSendBuf = s.Instantaneous.ByteSendBuf + item.MsSendBuf = s.Instantaneous.MsSendBuf + item.MsSendTsbPdDelay = s.Instantaneous.MsSendTsbPdDelay + item.PacketsReceiveBuf = s.Instantaneous.PktRecvBuf + item.BytesReceiveBuf = s.Instantaneous.ByteRecvBuf + item.MsReceiveBuf = s.Instantaneous.MsRecvBuf + item.MsReceiveTsbPdDelay = s.Instantaneous.MsRecvTsbPdDelay + item.PacketsReorderTolerance = s.Instantaneous.PktReorderTolerance + item.PacketsReceivedAvgBelatedTime = s.Instantaneous.PktRecvAvgBelatedTime + item.PacketsSendLossRate = s.Instantaneous.PktSendLossRate + item.PacketsReceivedLossRate = s.Instantaneous.PktRecvLossRate + } + + return item }