From 25a4f12dd57e9d41792e7b9961b700a72dd6fb0e Mon Sep 17 00:00:00 2001 From: danm Date: Tue, 31 Jan 2023 15:56:05 -0700 Subject: [PATCH] adding more labels for byte/packet counters --- pkg/telemetry/prometheus/packets.go | 8 +++++--- pkg/telemetry/stats.go | 8 ++++---- pkg/telemetry/statsconn.go | 12 ++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pkg/telemetry/prometheus/packets.go b/pkg/telemetry/prometheus/packets.go index ad7bcfd82..8ee79df48 100644 --- a/pkg/telemetry/prometheus/packets.go +++ b/pkg/telemetry/prometheus/packets.go @@ -28,7 +28,7 @@ var ( participantRTCConnected atomic.Uint64 participantRTCInit atomic.Uint64 - promPacketLabels = []string{"direction", "transmission"} + promPacketLabels = []string{"direction", "transmission", "region"} promPacketTotal *prometheus.CounterVec promPacketBytes *prometheus.CounterVec promRTCPLabels = []string{"direction"} @@ -128,10 +128,11 @@ func initPacketStats(nodeID string, nodeType livekit.NodeType) { prometheus.MustRegister(promConnections) } -func IncrementPackets(direction Direction, count uint64, retransmit bool) { +func IncrementPackets(direction Direction, count uint64, retransmit bool, region string) { promPacketTotal.WithLabelValues( string(direction), transmissionLabel(retransmit), + region, ).Add(float64(count)) if direction == Incoming { packetsIn.Add(count) @@ -143,10 +144,11 @@ func IncrementPackets(direction Direction, count uint64, retransmit bool) { } } -func IncrementBytes(direction Direction, count uint64, retransmit bool) { +func IncrementBytes(direction Direction, count uint64, retransmit bool, region string) { promPacketBytes.WithLabelValues( string(direction), transmissionLabel(retransmit), + region, ).Add(float64(count)) if direction == Incoming { bytesIn.Add(count) diff --git a/pkg/telemetry/stats.go b/pkg/telemetry/stats.go index 81e9c2556..2d2fbbbfa 100644 --- a/pkg/telemetry/stats.go +++ b/pkg/telemetry/stats.go @@ -68,13 +68,13 @@ func (t *telemetryService) TrackStats(key StatsKey, stat *livekit.AnalyticsStat) } } prometheus.IncrementRTCP(direction, nacks, plis, firs) - prometheus.IncrementPackets(direction, uint64(packets), false) - prometheus.IncrementBytes(direction, bytes, false) + prometheus.IncrementPackets(direction, uint64(packets), false, "") + prometheus.IncrementBytes(direction, bytes, false, "") if retransmitPackets != 0 { - prometheus.IncrementPackets(direction, uint64(retransmitPackets), true) + prometheus.IncrementPackets(direction, uint64(retransmitPackets), true, "") } if retransmitBytes != 0 { - prometheus.IncrementBytes(direction, retransmitBytes, true) + prometheus.IncrementBytes(direction, retransmitBytes, true, "") } if worker, ok := t.getWorker(key.participantID); ok { diff --git a/pkg/telemetry/statsconn.go b/pkg/telemetry/statsconn.go index 91f60af94..91916553f 100644 --- a/pkg/telemetry/statsconn.go +++ b/pkg/telemetry/statsconn.go @@ -38,7 +38,7 @@ func NewConn(c net.Conn, direction prometheus.Direction) *Conn { func (c *Conn) Read(b []byte) (n int, err error) { n, err = c.Conn.Read(b) if n > 0 { - prometheus.IncrementBytes(prometheus.Incoming, uint64(n), false) + prometheus.IncrementBytes(prometheus.Incoming, uint64(n), false, "") } return } @@ -46,7 +46,7 @@ func (c *Conn) Read(b []byte) (n int, err error) { func (c *Conn) Write(b []byte) (n int, err error) { n, err = c.Conn.Write(b) if n > 0 { - prometheus.IncrementBytes(prometheus.Outgoing, uint64(n), false) + prometheus.IncrementBytes(prometheus.Outgoing, uint64(n), false, "") } return } @@ -69,8 +69,8 @@ func NewPacketConn(c net.PacketConn, direction prometheus.Direction) *PacketConn func (c *PacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) { n, addr, err = c.PacketConn.ReadFrom(p) if n > 0 { - prometheus.IncrementBytes(prometheus.Incoming, uint64(n), false) - prometheus.IncrementPackets(prometheus.Incoming, 1, false) + prometheus.IncrementBytes(prometheus.Incoming, uint64(n), false, "") + prometheus.IncrementPackets(prometheus.Incoming, 1, false, "") } return } @@ -78,8 +78,8 @@ func (c *PacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) { func (c *PacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) { n, err = c.PacketConn.WriteTo(p, addr) if n > 0 { - prometheus.IncrementBytes(prometheus.Outgoing, uint64(n), false) - prometheus.IncrementPackets(prometheus.Outgoing, 1, false) + prometheus.IncrementBytes(prometheus.Outgoing, uint64(n), false, "") + prometheus.IncrementPackets(prometheus.Outgoing, 1, false, "") } return }