github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/remotewrite/queue_metrics.go (about) 1 package remotewrite 2 3 import ( 4 "fmt" 5 6 "github.com/prometheus/client_golang/prometheus" 7 ) 8 9 type queueMetrics struct { 10 reg prometheus.Registerer 11 12 numWorkers prometheus.Gauge 13 capacity prometheus.Gauge 14 pendingItems prometheus.Gauge 15 droppedItems prometheus.Counter 16 } 17 18 func newQueueMetrics(reg prometheus.Registerer, targetName, targetAddress string) *queueMetrics { 19 labels := prometheus.Labels{ 20 "target_name": targetName, 21 "target_address": targetAddress, 22 } 23 24 q := &queueMetrics{reg: reg} 25 // Suffix the subsystem with queue, since there will be other sub-subsystems (eg client) 26 subs := fmt.Sprintf("%s_queue", subsystem) 27 28 q.numWorkers = prometheus.NewGauge(prometheus.GaugeOpts{ 29 Namespace: namespace, 30 Subsystem: subs, 31 Name: "workers_total", 32 Help: "Total number of queue workers.", 33 ConstLabels: labels, 34 }) 35 36 q.capacity = prometheus.NewGauge(prometheus.GaugeOpts{ 37 Namespace: namespace, 38 Subsystem: subs, 39 Name: "capacity", 40 Help: "How many items the queue can hold.", 41 ConstLabels: labels, 42 }) 43 44 q.pendingItems = prometheus.NewGauge(prometheus.GaugeOpts{ 45 Namespace: namespace, 46 Subsystem: subs, 47 Name: "pending", 48 Help: "How many items are in the queue.", 49 ConstLabels: labels, 50 }) 51 52 q.droppedItems = prometheus.NewCounter(prometheus.CounterOpts{ 53 Namespace: namespace, 54 Subsystem: subs, 55 Name: "dropped", 56 Help: "How many items were dropped (as in not accepted into the queue).", 57 ConstLabels: labels, 58 }) 59 60 return q 61 } 62 63 func (q queueMetrics) mustRegister() { 64 q.reg.MustRegister( 65 q.numWorkers, 66 q.capacity, 67 q.pendingItems, 68 q.droppedItems, 69 ) 70 }