package webhook
import (
"sync"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
promWebhookDispatchTotal *prometheus.CounterVec
promWebhookQueueLengthHistogram prometheus.Histogram
promWebhookInitOnce sync.Once
)
func InitWebhookStats(constLabels prometheus.Labels) {
promWebhookInitOnce.Do(func() { initWebhookStats(constLabels) })
}
func initWebhookStats(constLabels prometheus.Labels) {
promWebhookDispatchTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "livekit",
Subsystem: "webhook",
Name: "dispatch_total",
ConstLabels: constLabels,
}, []string{"status", "reason"})
promWebhookQueueLengthHistogram = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: "livekit",
Subsystem: "webhook",
Name: "queue_length",
ConstLabels: constLabels,
Buckets: []float64{1, 2, 3, 4, 5, 10, 20, 40, 80},
})
}
func IncDispatchSuccess() {
promWebhookDispatchTotal.WithLabelValues("success", "").Inc()
}
func IncDispatchFailure() {
promWebhookDispatchTotal.WithLabelValues("failure", "").Inc()
}
func IncDispatchDrop(reason string) {
promWebhookDispatchTotal.WithLabelValues("drop", reason).Inc()
}
func RecordQueueLength(queueLength int) {
promWebhookQueueLengthHistogram.Observe(float64(queueLength))
}