/
metrics.go
167 lines (150 loc) · 4.66 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright (c) 2020 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package govppmux
import (
"sync/atomic"
"time"
"github.com/prometheus/client_golang/prometheus"
govppapi "go.fd.io/govpp/api"
)
// Set of raw Prometheus metrics.
// Labels
// * message
// * error
// Do not increment directly, use Report* methods.
var (
channelsCreated = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "ligato",
Subsystem: "govppmux",
Name: "channels_created_total",
Help: "The total number of created channels.",
})
channelsCount = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "ligato",
Subsystem: "govppmux",
Name: "channels",
Help: "The current number of opened channels.",
})
requestsSent = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "ligato",
Subsystem: "govppmux",
Name: "requests_total",
Help: "The total number of sent requests.",
},
[]string{"message"},
)
requestsCount = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "ligato",
Subsystem: "govppmux",
Name: "requests",
Help: "The current number of in-flight requests.",
})
requestsFailed = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "ligato",
Subsystem: "govppmux",
Name: "requests_failed_total",
Help: "The total number of failed requests.",
},
[]string{"message", "error"},
)
requestsDone = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "ligato",
Subsystem: "govppmux",
Name: "requests_done_total",
Help: "The total number of done requests.",
},
[]string{"message"},
)
repliesReceived = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "ligato",
Subsystem: "govppmux",
Name: "replies_received_total",
Help: "The total number of received replies.",
},
[]string{"message"},
)
successfulRequestHandlingSec = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "ligato",
Subsystem: "govppmux",
Name: "successful_request_duration_seconds",
Help: "Bucketed histogram of processing time of successfully handled requests by message name.",
// lowest bucket start of upper bound 0.0005 sec (0.5 ms) with factor 2
// highest bucket start of 0.0005 sec * 2^12 == 2.048 sec
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13),
},
[]string{"message"},
)
)
func init() {
prometheus.MustRegister(channelsCreated)
prometheus.MustRegister(channelsCount)
prometheus.MustRegister(requestsSent)
prometheus.MustRegister(requestsCount)
prometheus.MustRegister(requestsDone)
prometheus.MustRegister(requestsFailed)
prometheus.MustRegister(repliesReceived)
prometheus.MustRegister(successfulRequestHandlingSec)
}
func reportChannelsOpened() {
channelsCreated.Inc()
channelsCount.Inc()
if DisableOldStats {
return
}
atomic.AddUint64(&stats.ChannelsCreated, 1)
atomic.AddUint64(&stats.ChannelsOpen, 1)
}
func reportChannelsClosed() {
channelsCount.Dec()
if DisableOldStats {
return
}
atomic.AddUint64(&stats.ChannelsOpen, ^uint64(0)) // decrement
}
func reportRequestSent(request govppapi.Message) {
requestsCount.Inc()
requestsSent.WithLabelValues(request.GetMessageName()).Inc()
if DisableOldStats {
return
}
atomic.AddUint64(&stats.RequestsSent, 1)
}
func reportRequestFailed(request govppapi.Message, err error) {
requestsCount.Dec()
requestsFailed.WithLabelValues(request.GetMessageName(), err.Error()).Inc()
if DisableOldStats {
return
}
trackError(err.Error())
atomic.AddUint64(&stats.RequestsFail, 1)
}
func reportRequestSuccess(request govppapi.Message, startTime time.Time) {
took := time.Since(startTime)
requestsCount.Dec()
requestsDone.WithLabelValues(request.GetMessageName()).Inc()
successfulRequestHandlingSec.WithLabelValues(request.GetMessageName()).Observe(took.Seconds())
if DisableOldStats {
return
}
atomic.AddUint64(&stats.RequestsDone, 1)
trackMsgRequestDur(request.GetMessageName(), took)
}
func reportRepliesReceived(reply govppapi.Message) {
repliesReceived.WithLabelValues(reply.GetMessageName()).Inc()
if DisableOldStats {
return
}
atomic.AddUint64(&stats.RequestReplies, 1)
trackMsgReply(reply.GetMessageName())
}