github.com/livekit/protocol@v1.39.3/webhook/stats.go (about) 1 // Copyright 2023 LiveKit, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package webhook 16 17 import ( 18 "sync" 19 20 "github.com/prometheus/client_golang/prometheus" 21 "github.com/prometheus/client_golang/prometheus/promauto" 22 ) 23 24 var ( 25 promWebhookDispatchTotal *prometheus.CounterVec 26 promWebhookQueueLengthHistogram prometheus.Histogram 27 28 promWebhookInitOnce sync.Once 29 ) 30 31 func InitWebhookStats(constLabels prometheus.Labels) { 32 promWebhookInitOnce.Do(func() { initWebhookStats(constLabels) }) 33 } 34 35 func initWebhookStats(constLabels prometheus.Labels) { 36 promWebhookDispatchTotal = promauto.NewCounterVec(prometheus.CounterOpts{ 37 Namespace: "livekit", 38 Subsystem: "webhook", 39 Name: "dispatch_total", 40 ConstLabels: constLabels, 41 }, []string{"status", "reason"}) 42 43 promWebhookQueueLengthHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 44 Namespace: "livekit", 45 Subsystem: "webhook", 46 Name: "queue_length", 47 ConstLabels: constLabels, 48 Buckets: []float64{1, 2, 3, 4, 5, 10, 20, 40, 80}, 49 }) 50 } 51 52 func IncDispatchSuccess() { 53 promWebhookDispatchTotal.WithLabelValues("success", "").Inc() 54 } 55 56 func IncDispatchFailure() { 57 promWebhookDispatchTotal.WithLabelValues("failure", "").Inc() 58 } 59 60 func IncDispatchDrop(reason string) { 61 promWebhookDispatchTotal.WithLabelValues("drop", reason).Inc() 62 } 63 64 func RecordQueueLength(queueLength int) { 65 promWebhookQueueLengthHistogram.Observe(float64(queueLength)) 66 }