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:
Mathew Kamkar
2021-12-10 15:49:14 -08:00
committed by GitHub
parent d342335d09
commit bd42a39117
6 changed files with 88 additions and 71 deletions
+18 -11
View File
@@ -5,37 +5,44 @@ import (
"time"
livekit "github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/utils"
"github.com/prometheus/client_golang/prometheus"
)
const livekitNamespace = "livekit"
const livekitNamespace string = "livekit"
var (
MessageCounter *prometheus.CounterVec
ServiceOperationCounter *prometheus.CounterVec
)
func init() {
nodeID, _ := utils.LocalNodeID()
MessageCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: livekitNamespace,
Subsystem: "node",
Name: "messages",
Namespace: livekitNamespace,
Subsystem: "node",
Name: "messages",
ConstLabels: prometheus.Labels{"node_id": nodeID},
},
[]string{"type", "status"},
)
ServiceOperationCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: livekitNamespace,
Subsystem: "node",
Name: "service_operation",
Namespace: livekitNamespace,
Subsystem: "node",
Name: "service_operation",
ConstLabels: prometheus.Labels{"node_id": nodeID},
},
[]string{"type", "status", "error_type"},
)
)
func init() {
prometheus.MustRegister(MessageCounter)
prometheus.MustRegister(ServiceOperationCounter)
initPacketStats()
initRoomStats()
initPacketStats(nodeID)
initRoomStats(nodeID)
}
func UpdateCurrentNodeStats(nodeStats *livekit.NodeStats) error {