Include node ID with Prometheus metrics (#251)
* include node id in prometheus metrics * static prom init and nodeID * update protocol dep
This commit is contained in:
@@ -14,8 +14,7 @@ require (
|
|||||||
github.com/google/wire v0.5.0
|
github.com/google/wire v0.5.0
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/hashicorp/golang-lru v0.5.4
|
github.com/hashicorp/golang-lru v0.5.4
|
||||||
github.com/jxskiss/base62 v0.0.0-20191017122030-4f11678b909b
|
github.com/livekit/protocol v0.11.1-0.20211210234141-81dc05762739
|
||||||
github.com/livekit/protocol v0.11.0
|
|
||||||
github.com/magefile/mage v1.11.0
|
github.com/magefile/mage v1.11.0
|
||||||
github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0
|
github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0
|
||||||
github.com/mitchellh/go-homedir v1.1.0
|
github.com/mitchellh/go-homedir v1.1.0
|
||||||
@@ -54,6 +53,7 @@ require (
|
|||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
github.com/google/subcommands v1.2.0 // indirect
|
github.com/google/subcommands v1.2.0 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
github.com/jxskiss/base62 v0.0.0-20191017122030-4f11678b909b // indirect
|
||||||
github.com/lithammer/shortuuid/v3 v3.0.6 // indirect
|
github.com/lithammer/shortuuid/v3 v3.0.6 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||||
|
|||||||
@@ -132,8 +132,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/lithammer/shortuuid/v3 v3.0.6 h1:pr15YQyvhiSX/qPxncFtqk+v4xLEpOZObbsY/mKrcvA=
|
github.com/lithammer/shortuuid/v3 v3.0.6 h1:pr15YQyvhiSX/qPxncFtqk+v4xLEpOZObbsY/mKrcvA=
|
||||||
github.com/lithammer/shortuuid/v3 v3.0.6/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts=
|
github.com/lithammer/shortuuid/v3 v3.0.6/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts=
|
||||||
github.com/livekit/protocol v0.11.0 h1:6yJnvz2ZjkAB51tjBpUjem+pZW8Y4NSHPRT/GAdxOHs=
|
github.com/livekit/protocol v0.11.1-0.20211210234141-81dc05762739 h1:/y/ve7kJ+2aJkhzn5n4jwzPMI4Jow8TUFp63uXsUP64=
|
||||||
github.com/livekit/protocol v0.11.0/go.mod h1:YoHW9YbWbPnuVsgwBB4hAINKT+V68jmfh9zXBSSn6Wg=
|
github.com/livekit/protocol v0.11.1-0.20211210234141-81dc05762739/go.mod h1:YoHW9YbWbPnuVsgwBB4hAINKT+V68jmfh9zXBSSn6Wg=
|
||||||
github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls=
|
github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls=
|
||||||
github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
|
github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
|
||||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||||
|
|||||||
+5
-16
@@ -1,13 +1,9 @@
|
|||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha1"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jxskiss/base62"
|
|
||||||
livekit "github.com/livekit/protocol/livekit"
|
livekit "github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/utils"
|
"github.com/livekit/protocol/utils"
|
||||||
|
|
||||||
@@ -17,15 +13,15 @@ import (
|
|||||||
type LocalNode *livekit.Node
|
type LocalNode *livekit.Node
|
||||||
|
|
||||||
func NewLocalNode(conf *config.Config) (LocalNode, error) {
|
func NewLocalNode(conf *config.Config) (LocalNode, error) {
|
||||||
hostname, err := os.Hostname()
|
nodeID, err := utils.LocalNodeID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if conf.RTC.NodeIP == "" {
|
if conf.RTC.NodeIP == "" {
|
||||||
return nil, ErrIPNotSet
|
return nil, ErrIPNotSet
|
||||||
}
|
}
|
||||||
return &livekit.Node{
|
node := &livekit.Node{
|
||||||
Id: fmt.Sprintf("%s%s", utils.NodePrefix, HashedID(hostname)[:8]),
|
Id: nodeID,
|
||||||
Ip: conf.RTC.NodeIP,
|
Ip: conf.RTC.NodeIP,
|
||||||
NumCpus: uint32(runtime.NumCPU()),
|
NumCpus: uint32(runtime.NumCPU()),
|
||||||
Region: conf.Region,
|
Region: conf.Region,
|
||||||
@@ -34,14 +30,7 @@ func NewLocalNode(conf *config.Config) (LocalNode, error) {
|
|||||||
StartedAt: time.Now().Unix(),
|
StartedAt: time.Now().Unix(),
|
||||||
UpdatedAt: time.Now().Unix(),
|
UpdatedAt: time.Now().Unix(),
|
||||||
},
|
},
|
||||||
}, nil
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Creates a hashed ID from a unique string
|
return node, nil
|
||||||
func HashedID(id string) string {
|
|
||||||
h := sha1.New()
|
|
||||||
h.Write([]byte(id))
|
|
||||||
val := h.Sum(nil)
|
|
||||||
|
|
||||||
return base62.EncodeToString(val)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,37 +5,44 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
livekit "github.com/livekit/protocol/livekit"
|
livekit "github.com/livekit/protocol/livekit"
|
||||||
|
"github.com/livekit/protocol/utils"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const livekitNamespace = "livekit"
|
const livekitNamespace string = "livekit"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
MessageCounter *prometheus.CounterVec
|
||||||
|
ServiceOperationCounter *prometheus.CounterVec
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
nodeID, _ := utils.LocalNodeID()
|
||||||
MessageCounter = prometheus.NewCounterVec(
|
MessageCounter = prometheus.NewCounterVec(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Namespace: livekitNamespace,
|
Namespace: livekitNamespace,
|
||||||
Subsystem: "node",
|
Subsystem: "node",
|
||||||
Name: "messages",
|
Name: "messages",
|
||||||
|
ConstLabels: prometheus.Labels{"node_id": nodeID},
|
||||||
},
|
},
|
||||||
[]string{"type", "status"},
|
[]string{"type", "status"},
|
||||||
)
|
)
|
||||||
|
|
||||||
ServiceOperationCounter = prometheus.NewCounterVec(
|
ServiceOperationCounter = prometheus.NewCounterVec(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Namespace: livekitNamespace,
|
Namespace: livekitNamespace,
|
||||||
Subsystem: "node",
|
Subsystem: "node",
|
||||||
Name: "service_operation",
|
Name: "service_operation",
|
||||||
|
ConstLabels: prometheus.Labels{"node_id": nodeID},
|
||||||
},
|
},
|
||||||
[]string{"type", "status", "error_type"},
|
[]string{"type", "status", "error_type"},
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
prometheus.MustRegister(MessageCounter)
|
prometheus.MustRegister(MessageCounter)
|
||||||
prometheus.MustRegister(ServiceOperationCounter)
|
prometheus.MustRegister(ServiceOperationCounter)
|
||||||
|
|
||||||
initPacketStats()
|
initPacketStats(nodeID)
|
||||||
initRoomStats()
|
initRoomStats(nodeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateCurrentNodeStats(nodeStats *livekit.NodeStats) error {
|
func UpdateCurrentNodeStats(nodeStats *livekit.NodeStats) error {
|
||||||
|
|||||||
@@ -22,34 +22,45 @@ var (
|
|||||||
|
|
||||||
promPacketLabels = []string{"direction"}
|
promPacketLabels = []string{"direction"}
|
||||||
|
|
||||||
promPacketTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
promPacketTotal *prometheus.CounterVec
|
||||||
Namespace: livekitNamespace,
|
promPacketBytes *prometheus.CounterVec
|
||||||
Subsystem: "packet",
|
promNackTotal *prometheus.CounterVec
|
||||||
Name: "total",
|
promPliTotal *prometheus.CounterVec
|
||||||
}, promPacketLabels)
|
promFirTotal *prometheus.CounterVec
|
||||||
promPacketBytes = prometheus.NewCounterVec(prometheus.CounterOpts{
|
|
||||||
Namespace: livekitNamespace,
|
|
||||||
Subsystem: "packet",
|
|
||||||
Name: "bytes",
|
|
||||||
}, promPacketLabels)
|
|
||||||
promNackTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
|
||||||
Namespace: livekitNamespace,
|
|
||||||
Subsystem: "nack",
|
|
||||||
Name: "total",
|
|
||||||
}, promPacketLabels)
|
|
||||||
promPliTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
|
||||||
Namespace: livekitNamespace,
|
|
||||||
Subsystem: "pli",
|
|
||||||
Name: "total",
|
|
||||||
}, promPacketLabels)
|
|
||||||
promFirTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
|
||||||
Namespace: livekitNamespace,
|
|
||||||
Subsystem: "fir",
|
|
||||||
Name: "total",
|
|
||||||
}, promPacketLabels)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func initPacketStats() {
|
func initPacketStats(nodeID string) {
|
||||||
|
promPacketTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
Namespace: livekitNamespace,
|
||||||
|
Subsystem: "packet",
|
||||||
|
Name: "total",
|
||||||
|
ConstLabels: prometheus.Labels{"node_id": nodeID},
|
||||||
|
}, promPacketLabels)
|
||||||
|
promPacketBytes = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
Namespace: livekitNamespace,
|
||||||
|
Subsystem: "packet",
|
||||||
|
Name: "bytes",
|
||||||
|
ConstLabels: prometheus.Labels{"node_id": nodeID},
|
||||||
|
}, promPacketLabels)
|
||||||
|
promNackTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
Namespace: livekitNamespace,
|
||||||
|
Subsystem: "nack",
|
||||||
|
Name: "total",
|
||||||
|
ConstLabels: prometheus.Labels{"node_id": nodeID},
|
||||||
|
}, promPacketLabels)
|
||||||
|
promPliTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
Namespace: livekitNamespace,
|
||||||
|
Subsystem: "pli",
|
||||||
|
Name: "total",
|
||||||
|
ConstLabels: prometheus.Labels{"node_id": nodeID},
|
||||||
|
}, promPacketLabels)
|
||||||
|
promFirTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
Namespace: livekitNamespace,
|
||||||
|
Subsystem: "fir",
|
||||||
|
Name: "total",
|
||||||
|
ConstLabels: prometheus.Labels{"node_id": nodeID},
|
||||||
|
}, promPacketLabels)
|
||||||
|
|
||||||
prometheus.MustRegister(promPacketTotal)
|
prometheus.MustRegister(promPacketTotal)
|
||||||
prometheus.MustRegister(promPacketBytes)
|
prometheus.MustRegister(promPacketBytes)
|
||||||
prometheus.MustRegister(promNackTotal)
|
prometheus.MustRegister(promNackTotal)
|
||||||
|
|||||||
@@ -13,37 +13,47 @@ var (
|
|||||||
atomicTrackPublishedTotal int32
|
atomicTrackPublishedTotal int32
|
||||||
atomicTrackSubscribedTotal int32
|
atomicTrackSubscribedTotal int32
|
||||||
|
|
||||||
|
promRoomTotal prometheus.Gauge
|
||||||
|
promRoomDuration prometheus.Histogram
|
||||||
|
promParticipantTotal prometheus.Gauge
|
||||||
|
promTrackPublishedTotal *prometheus.GaugeVec
|
||||||
|
promTrackSubscribedTotal *prometheus.GaugeVec
|
||||||
|
)
|
||||||
|
|
||||||
|
func initRoomStats(nodeID string) {
|
||||||
promRoomTotal = prometheus.NewGauge(prometheus.GaugeOpts{
|
promRoomTotal = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Namespace: livekitNamespace,
|
Namespace: livekitNamespace,
|
||||||
Subsystem: "room",
|
Subsystem: "room",
|
||||||
Name: "total",
|
Name: "total",
|
||||||
})
|
})
|
||||||
promRoomDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
|
promRoomDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
|
||||||
Namespace: livekitNamespace,
|
Namespace: livekitNamespace,
|
||||||
Subsystem: "room",
|
Subsystem: "room",
|
||||||
Name: "duration_seconds",
|
Name: "duration_seconds",
|
||||||
|
ConstLabels: prometheus.Labels{"node_id": nodeID},
|
||||||
Buckets: []float64{
|
Buckets: []float64{
|
||||||
5, 10, 60, 5 * 60, 10 * 60, 30 * 60, 60 * 60, 2 * 60 * 60, 5 * 60 * 60, 10 * 60 * 60,
|
5, 10, 60, 5 * 60, 10 * 60, 30 * 60, 60 * 60, 2 * 60 * 60, 5 * 60 * 60, 10 * 60 * 60,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
promParticipantTotal = prometheus.NewGauge(prometheus.GaugeOpts{
|
promParticipantTotal = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Namespace: livekitNamespace,
|
Namespace: livekitNamespace,
|
||||||
Subsystem: "participant",
|
Subsystem: "participant",
|
||||||
Name: "total",
|
Name: "total",
|
||||||
|
ConstLabels: prometheus.Labels{"node_id": nodeID},
|
||||||
})
|
})
|
||||||
promTrackPublishedTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
promTrackPublishedTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Namespace: livekitNamespace,
|
Namespace: livekitNamespace,
|
||||||
Subsystem: "track",
|
Subsystem: "track",
|
||||||
Name: "published_total",
|
Name: "published_total",
|
||||||
|
ConstLabels: prometheus.Labels{"node_id": nodeID},
|
||||||
}, []string{"kind"})
|
}, []string{"kind"})
|
||||||
promTrackSubscribedTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
promTrackSubscribedTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Namespace: livekitNamespace,
|
Namespace: livekitNamespace,
|
||||||
Subsystem: "track",
|
Subsystem: "track",
|
||||||
Name: "subscribed_total",
|
Name: "subscribed_total",
|
||||||
|
ConstLabels: prometheus.Labels{"node_id": nodeID},
|
||||||
}, []string{"kind"})
|
}, []string{"kind"})
|
||||||
)
|
|
||||||
|
|
||||||
func initRoomStats() {
|
|
||||||
prometheus.MustRegister(promRoomTotal)
|
prometheus.MustRegister(promRoomTotal)
|
||||||
prometheus.MustRegister(promRoomDuration)
|
prometheus.MustRegister(promRoomDuration)
|
||||||
prometheus.MustRegister(promParticipantTotal)
|
prometheus.MustRegister(promParticipantTotal)
|
||||||
|
|||||||
Reference in New Issue
Block a user