@@ -17,6 +17,7 @@ limitations under the License.
17
17
package metrics
18
18
19
19
import (
20
+ "strconv"
20
21
"time"
21
22
22
23
"github.com/prometheus/client_golang/prometheus"
@@ -57,6 +58,8 @@ type AgentMetrics struct {
57
58
endpointConnections * prometheus.GaugeVec
58
59
streamPackets * prometheus.CounterVec
59
60
streamErrors * prometheus.CounterVec
61
+ leaseLists * prometheus.CounterVec
62
+ leaseListLatencies * prometheus.HistogramVec
60
63
}
61
64
62
65
// newAgentMetrics create a new AgentMetrics, configured with default metric names.
@@ -116,6 +119,25 @@ func newAgentMetrics() *AgentMetrics {
116
119
},
117
120
[]string {},
118
121
)
122
+ leaseLists := prometheus .NewCounterVec (
123
+ prometheus.CounterOpts {
124
+ Namespace : Namespace ,
125
+ Subsystem : Subsystem ,
126
+ Name : "lease_lists_total" ,
127
+ Help : "Count of server lease list calls made by the agent to the k8s apiserver, labeled by HTTP response code and reason" ,
128
+ },
129
+ []string {"http_response_code" , "reason" },
130
+ )
131
+ leaseListLatencies := prometheus .NewHistogramVec (
132
+ prometheus.HistogramOpts {
133
+ Namespace : Namespace ,
134
+ Subsystem : Subsystem ,
135
+ Name : "lease_list_latency_seconds" ,
136
+ Help : "Latency of server lease listing in seconds" ,
137
+ Buckets : latencyBuckets ,
138
+ },
139
+ []string {},
140
+ )
119
141
streamPackets := commonmetrics .MakeStreamPacketsTotalMetric (Namespace , Subsystem )
120
142
streamErrors := commonmetrics .MakeStreamErrorsTotalMetric (Namespace , Subsystem )
121
143
prometheus .MustRegister (dialLatencies )
@@ -126,6 +148,8 @@ func newAgentMetrics() *AgentMetrics {
126
148
prometheus .MustRegister (streamPackets )
127
149
prometheus .MustRegister (streamErrors )
128
150
prometheus .MustRegister (serverCount )
151
+ prometheus .MustRegister (leaseLists )
152
+ prometheus .MustRegister (leaseListLatencies )
129
153
return & AgentMetrics {
130
154
dialLatencies : dialLatencies ,
131
155
serverFailures : serverFailures ,
@@ -135,6 +159,8 @@ func newAgentMetrics() *AgentMetrics {
135
159
streamPackets : streamPackets ,
136
160
streamErrors : streamErrors ,
137
161
serverCount : serverCount ,
162
+ leaseLists : leaseLists ,
163
+ leaseListLatencies : leaseListLatencies ,
138
164
}
139
165
140
166
}
@@ -148,6 +174,9 @@ func (a *AgentMetrics) Reset() {
148
174
a .endpointConnections .Reset ()
149
175
a .streamPackets .Reset ()
150
176
a .streamErrors .Reset ()
177
+ a .serverCount .Reset ()
178
+ a .leaseLists .Reset ()
179
+ a .leaseListLatencies .Reset ()
151
180
}
152
181
153
182
// ObserveServerFailure records a failure to send to or receive from the proxy
@@ -181,6 +210,14 @@ func (a *AgentMetrics) SetServerCount(count int) {
181
210
a .serverCount .WithLabelValues ().Set (float64 (count ))
182
211
}
183
212
213
+ func (a * AgentMetrics ) ObserveLeaseList (httpCode int , reason string ) {
214
+ a .leaseLists .WithLabelValues (strconv .Itoa (httpCode ), reason ).Inc ()
215
+ }
216
+
217
+ func (a * AgentMetrics ) ObserveLeaseListLatency (latency time.Duration ) {
218
+ a .leaseListLatencies .WithLabelValues ().Observe (latency .Seconds ())
219
+ }
220
+
184
221
// EndpointConnectionInc increments a new endpoint connection.
185
222
func (a * AgentMetrics ) EndpointConnectionInc () {
186
223
a .endpointConnections .WithLabelValues ().Inc ()
0 commit comments