github.com/MetalBlockchain/metalgo@v1.11.9/snow/networking/handler/message_queue_metrics.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package handler 5 6 import ( 7 "errors" 8 9 "github.com/prometheus/client_golang/prometheus" 10 11 "github.com/MetalBlockchain/metalgo/utils/metric" 12 ) 13 14 const opLabel = "op" 15 16 var opLabels = []string{opLabel} 17 18 type messageQueueMetrics struct { 19 count *prometheus.GaugeVec 20 nodesWithMessages prometheus.Gauge 21 numExcessiveCPU prometheus.Counter 22 } 23 24 func (m *messageQueueMetrics) initialize( 25 metricsNamespace string, 26 metricsRegisterer prometheus.Registerer, 27 ) error { 28 namespace := metric.AppendNamespace(metricsNamespace, "unprocessed_msgs") 29 m.count = prometheus.NewGaugeVec( 30 prometheus.GaugeOpts{ 31 Namespace: namespace, 32 Name: "count", 33 Help: "messages in the queue", 34 }, 35 opLabels, 36 ) 37 m.nodesWithMessages = prometheus.NewGauge(prometheus.GaugeOpts{ 38 Namespace: namespace, 39 Name: "nodes", 40 Help: "nodes with at least 1 message ready to be processed", 41 }) 42 m.numExcessiveCPU = prometheus.NewCounter(prometheus.CounterOpts{ 43 Namespace: namespace, 44 Name: "excessive_cpu", 45 Help: "times a message has been deferred due to excessive CPU usage", 46 }) 47 48 return errors.Join( 49 metricsRegisterer.Register(m.count), 50 metricsRegisterer.Register(m.nodesWithMessages), 51 metricsRegisterer.Register(m.numExcessiveCPU), 52 ) 53 }