go.ligato.io/vpp-agent/v3@v3.5.0/plugins/govppmux/metrics.go (about) 1 // Copyright (c) 2020 Cisco and/or its affiliates. 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 govppmux 16 17 import ( 18 "sync/atomic" 19 "time" 20 21 "github.com/prometheus/client_golang/prometheus" 22 govppapi "go.fd.io/govpp/api" 23 ) 24 25 // Set of raw Prometheus metrics. 26 // Labels 27 // * message 28 // * error 29 // Do not increment directly, use Report* methods. 30 var ( 31 channelsCreated = prometheus.NewCounter(prometheus.CounterOpts{ 32 Namespace: "ligato", 33 Subsystem: "govppmux", 34 Name: "channels_created_total", 35 Help: "The total number of created channels.", 36 }) 37 channelsCount = prometheus.NewGauge(prometheus.GaugeOpts{ 38 Namespace: "ligato", 39 Subsystem: "govppmux", 40 Name: "channels", 41 Help: "The current number of opened channels.", 42 }) 43 requestsSent = prometheus.NewCounterVec(prometheus.CounterOpts{ 44 Namespace: "ligato", 45 Subsystem: "govppmux", 46 Name: "requests_total", 47 Help: "The total number of sent requests.", 48 }, 49 []string{"message"}, 50 ) 51 requestsCount = prometheus.NewGauge(prometheus.GaugeOpts{ 52 Namespace: "ligato", 53 Subsystem: "govppmux", 54 Name: "requests", 55 Help: "The current number of in-flight requests.", 56 }) 57 requestsFailed = prometheus.NewCounterVec(prometheus.CounterOpts{ 58 Namespace: "ligato", 59 Subsystem: "govppmux", 60 Name: "requests_failed_total", 61 Help: "The total number of failed requests.", 62 }, 63 []string{"message", "error"}, 64 ) 65 requestsDone = prometheus.NewCounterVec(prometheus.CounterOpts{ 66 Namespace: "ligato", 67 Subsystem: "govppmux", 68 Name: "requests_done_total", 69 Help: "The total number of done requests.", 70 }, 71 []string{"message"}, 72 ) 73 repliesReceived = prometheus.NewCounterVec(prometheus.CounterOpts{ 74 Namespace: "ligato", 75 Subsystem: "govppmux", 76 Name: "replies_received_total", 77 Help: "The total number of received replies.", 78 }, 79 []string{"message"}, 80 ) 81 successfulRequestHandlingSec = prometheus.NewHistogramVec(prometheus.HistogramOpts{ 82 Namespace: "ligato", 83 Subsystem: "govppmux", 84 Name: "successful_request_duration_seconds", 85 Help: "Bucketed histogram of processing time of successfully handled requests by message name.", 86 // lowest bucket start of upper bound 0.0005 sec (0.5 ms) with factor 2 87 // highest bucket start of 0.0005 sec * 2^12 == 2.048 sec 88 Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13), 89 }, 90 []string{"message"}, 91 ) 92 ) 93 94 func init() { 95 prometheus.MustRegister(channelsCreated) 96 prometheus.MustRegister(channelsCount) 97 prometheus.MustRegister(requestsSent) 98 prometheus.MustRegister(requestsCount) 99 prometheus.MustRegister(requestsDone) 100 prometheus.MustRegister(requestsFailed) 101 prometheus.MustRegister(repliesReceived) 102 prometheus.MustRegister(successfulRequestHandlingSec) 103 } 104 105 func reportChannelsOpened() { 106 channelsCreated.Inc() 107 channelsCount.Inc() 108 109 if DisableOldStats { 110 return 111 } 112 atomic.AddUint64(&stats.ChannelsCreated, 1) 113 atomic.AddUint64(&stats.ChannelsOpen, 1) 114 } 115 116 func reportChannelsClosed() { 117 channelsCount.Dec() 118 119 if DisableOldStats { 120 return 121 } 122 atomic.AddUint64(&stats.ChannelsOpen, ^uint64(0)) // decrement 123 } 124 125 func reportRequestSent(request govppapi.Message) { 126 requestsCount.Inc() 127 requestsSent.WithLabelValues(request.GetMessageName()).Inc() 128 129 if DisableOldStats { 130 return 131 } 132 atomic.AddUint64(&stats.RequestsSent, 1) 133 } 134 135 func reportRequestFailed(request govppapi.Message, err error) { 136 requestsCount.Dec() 137 requestsFailed.WithLabelValues(request.GetMessageName(), err.Error()).Inc() 138 139 if DisableOldStats { 140 return 141 } 142 trackError(err.Error()) 143 atomic.AddUint64(&stats.RequestsFail, 1) 144 } 145 146 func reportRequestSuccess(request govppapi.Message, startTime time.Time) { 147 took := time.Since(startTime) 148 requestsCount.Dec() 149 requestsDone.WithLabelValues(request.GetMessageName()).Inc() 150 successfulRequestHandlingSec.WithLabelValues(request.GetMessageName()).Observe(took.Seconds()) 151 152 if DisableOldStats { 153 return 154 } 155 atomic.AddUint64(&stats.RequestsDone, 1) 156 trackMsgRequestDur(request.GetMessageName(), took) 157 } 158 159 func reportRepliesReceived(reply govppapi.Message) { 160 repliesReceived.WithLabelValues(reply.GetMessageName()).Inc() 161 162 if DisableOldStats { 163 return 164 } 165 atomic.AddUint64(&stats.RequestReplies, 1) 166 trackMsgReply(reply.GetMessageName()) 167 }