@@ -62,11 +62,44 @@ var (
6262 Buckets : prometheus .ExponentialBuckets (0.001 , 2 , 10 ),
6363 }, []string {"verb" , "url" })
6464
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" })
65+ // requestLatency is a Prometheus Histogram metric type partitioned by
66+ // "verb", and "host" labels. It is used for the rest client latency metrics.
67+ requestLatency = prometheus .NewHistogramVec (
68+ prometheus.HistogramOpts {
69+ Name : "rest_client_request_duration_seconds" ,
70+ Help : "Request latency in seconds. Broken down by verb, and host." ,
71+ 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 },
72+ },
73+ []string {"verb" , "host" },
74+ )
75+
76+ requestSize = prometheus .NewHistogramVec (
77+ prometheus.HistogramOpts {
78+ Name : "rest_client_request_size_bytes" ,
79+ Help : "Request size in bytes. Broken down by verb and host." ,
80+ // 64 bytes to 16MB
81+ Buckets : []float64 {64 , 256 , 512 , 1024 , 4096 , 16384 , 65536 , 262144 , 1048576 , 4194304 , 16777216 },
82+ },
83+ []string {"verb" , "host" },
84+ )
85+
86+ responseSize = prometheus .NewHistogramVec (
87+ prometheus.HistogramOpts {
88+ Name : "rest_client_response_size_bytes" ,
89+ Help : "Response size in bytes. Broken down by verb and host." ,
90+ // 64 bytes to 16MB
91+ Buckets : []float64 {64 , 256 , 512 , 1024 , 4096 , 16384 , 65536 , 262144 , 1048576 , 4194304 , 16777216 },
92+ },
93+ []string {"verb" , "host" },
94+ )
95+
96+ requestResult = prometheus .NewCounterVec (
97+ prometheus.CounterOpts {
98+ Name : "rest_client_requests_total" ,
99+ Help : "Number of HTTP requests, partitioned by status code, method, and host." ,
100+ },
101+ []string {"code" , "method" , "host" },
102+ )
70103)
71104
72105func init () {
@@ -76,11 +109,17 @@ func init() {
76109// registerClientMetrics sets up the client latency metrics from client-go.
77110func registerClientMetrics () {
78111 // register the metrics with our registry
112+ Registry .MustRegister (requestLatency )
113+ Registry .MustRegister (requestSize )
114+ Registry .MustRegister (responseSize )
79115 Registry .MustRegister (requestResult )
80116
81117 // register the metrics with client-go
82118 clientmetrics .Register (clientmetrics.RegisterOpts {
83- RequestResult : & resultAdapter {metric : requestResult },
119+ RequestLatency : & LatencyAdapter {metric : requestLatency },
120+ RequestSize : & sizeAdapter {metric : requestSize },
121+ ResponseSize : & sizeAdapter {metric : responseSize },
122+ RequestResult : & resultAdapter {metric : requestResult },
84123 })
85124}
86125
@@ -102,6 +141,14 @@ func (l *LatencyAdapter) Observe(_ context.Context, verb string, u url.URL, late
102141 l .metric .WithLabelValues (verb , u .String ()).Observe (latency .Seconds ())
103142}
104143
144+ type sizeAdapter struct {
145+ metric * prometheus.HistogramVec
146+ }
147+
148+ func (s * sizeAdapter ) Observe (ctx context.Context , verb string , host string , size float64 ) {
149+ s .metric .WithLabelValues (verb , host ).Observe (size )
150+ }
151+
105152type resultAdapter struct {
106153 metric * prometheus.CounterVec
107154}
0 commit comments