@@ -33,7 +33,6 @@ import (
33
33
const (
34
34
RestClientSubsystem = "rest_client"
35
35
LatencyKey = "request_latency_seconds"
36
- ResultKey = "requests_total"
37
36
)
38
37
39
38
var (
@@ -62,11 +61,44 @@ var (
62
61
Buckets : prometheus .ExponentialBuckets (0.001 , 2 , 10 ),
63
62
}, []string {"verb" , "url" })
64
63
65
- requestResult = prometheus .NewCounterVec (prometheus.CounterOpts {
66
- Subsystem : RestClientSubsystem ,
67
- Name : ResultKey ,
68
- Help : "Number of HTTP requests, partitioned by status code, method, and host." ,
69
- }, []string {"code" , "method" , "host" })
64
+ // requestLatency is a Prometheus Histogram metric type partitioned by
65
+ // "verb", and "host" labels. It is used for the rest client latency metrics.
66
+ requestLatency = prometheus .NewHistogramVec (
67
+ prometheus.HistogramOpts {
68
+ Name : "rest_client_request_duration_seconds" ,
69
+ Help : "Request latency in seconds. Broken down by verb, and host." ,
70
+ Buckets : []float64 {0.005 , 0.025 , 0.1 , 0.25 , 0.5 , 1.0 , 2.0 , 4.0 , 8.0 , 15.0 , 30.0 , 60.0 },
71
+ },
72
+ []string {"verb" , "host" },
73
+ )
74
+
75
+ requestSize = prometheus .NewHistogramVec (
76
+ prometheus.HistogramOpts {
77
+ Name : "rest_client_request_size_bytes" ,
78
+ Help : "Request size in bytes. Broken down by verb and host." ,
79
+ // 64 bytes to 16MB
80
+ Buckets : []float64 {64 , 256 , 512 , 1024 , 4096 , 16384 , 65536 , 262144 , 1048576 , 4194304 , 16777216 },
81
+ },
82
+ []string {"verb" , "host" },
83
+ )
84
+
85
+ responseSize = prometheus .NewHistogramVec (
86
+ prometheus.HistogramOpts {
87
+ Name : "rest_client_response_size_bytes" ,
88
+ Help : "Response size in bytes. Broken down by verb and host." ,
89
+ // 64 bytes to 16MB
90
+ Buckets : []float64 {64 , 256 , 512 , 1024 , 4096 , 16384 , 65536 , 262144 , 1048576 , 4194304 , 16777216 },
91
+ },
92
+ []string {"verb" , "host" },
93
+ )
94
+
95
+ requestResult = prometheus .NewCounterVec (
96
+ prometheus.CounterOpts {
97
+ Name : "rest_client_requests_total" ,
98
+ Help : "Number of HTTP requests, partitioned by status code, method, and host." ,
99
+ },
100
+ []string {"code" , "method" , "host" },
101
+ )
70
102
)
71
103
72
104
func init () {
@@ -76,11 +108,17 @@ func init() {
76
108
// registerClientMetrics sets up the client latency metrics from client-go.
77
109
func registerClientMetrics () {
78
110
// register the metrics with our registry
111
+ Registry .MustRegister (requestLatency )
112
+ Registry .MustRegister (requestSize )
113
+ Registry .MustRegister (responseSize )
79
114
Registry .MustRegister (requestResult )
80
115
81
116
// register the metrics with client-go
82
117
clientmetrics .Register (clientmetrics.RegisterOpts {
83
- RequestResult : & resultAdapter {metric : requestResult },
118
+ RequestLatency : & LatencyAdapter {metric : requestLatency },
119
+ RequestSize : & sizeAdapter {metric : requestSize },
120
+ ResponseSize : & sizeAdapter {metric : responseSize },
121
+ RequestResult : & resultAdapter {metric : requestResult },
84
122
})
85
123
}
86
124
@@ -102,6 +140,14 @@ func (l *LatencyAdapter) Observe(_ context.Context, verb string, u url.URL, late
102
140
l .metric .WithLabelValues (verb , u .String ()).Observe (latency .Seconds ())
103
141
}
104
142
143
+ type sizeAdapter struct {
144
+ metric * prometheus.HistogramVec
145
+ }
146
+
147
+ func (s * sizeAdapter ) Observe (ctx context.Context , verb string , host string , size float64 ) {
148
+ s .metric .WithLabelValues (verb , host ).Observe (size )
149
+ }
150
+
105
151
type resultAdapter struct {
106
152
metric * prometheus.CounterVec
107
153
}
0 commit comments