diff --git a/cmd/gateway-common.go b/cmd/gateway-common.go index 3171b0705..f1624f437 100644 --- a/cmd/gateway-common.go +++ b/cmd/gateway-common.go @@ -432,7 +432,7 @@ type MetricsTransport struct { // RoundTrip implements the RoundTrip method for MetricsTransport func (m MetricsTransport) RoundTrip(r *http.Request) (*http.Response, error) { metered := shouldMeterRequest(r) - if metered && (r.Method == http.MethodGet || r.Method == http.MethodHead) { + if metered && (r.Method == http.MethodPost || r.Method == http.MethodPut) { m.Metrics.IncRequests(r.Method) if r.ContentLength > 0 { m.Metrics.IncBytesSent(uint64(r.ContentLength)) @@ -444,7 +444,8 @@ func (m MetricsTransport) RoundTrip(r *http.Request) (*http.Response, error) { return nil, err } if metered && (r.Method == http.MethodGet || r.Method == http.MethodHead) { - if r.ContentLength > 0 { + m.Metrics.IncRequests(r.Method) + if resp.ContentLength > 0 { m.Metrics.IncBytesReceived(uint64(resp.ContentLength)) } } diff --git a/cmd/gateway-metrics.go b/cmd/gateway-metrics.go index 73160522e..4f86cf96c 100644 --- a/cmd/gateway-metrics.go +++ b/cmd/gateway-metrics.go @@ -26,6 +26,8 @@ import ( type RequestStats struct { Get atomic.Uint64 `json:"Get"` Head atomic.Uint64 `json:"Head"` + Put atomic.Uint64 `json:"Put"` + Post atomic.Uint64 `json:"Post"` } // Metrics - represents bytes served from backend @@ -63,6 +65,10 @@ func (s *Metrics) IncRequests(method string) { s.requestStats.Get.Add(1) } else if method == http.MethodHead { s.requestStats.Head.Add(1) + } else if method == http.MethodPut { + s.requestStats.Put.Add(1) + } else if method == http.MethodPost { + s.requestStats.Post.Add(1) } } diff --git a/cmd/metrics.go b/cmd/metrics.go index 9f5b4bf60..01bd1e639 100644 --- a/cmd/metrics.go +++ b/cmd/metrics.go @@ -203,6 +203,24 @@ func gatewayMetricsPrometheus(ch chan<- prometheus.Metric) { float64(s.Head.Load()), http.MethodHead, ) + ch <- prometheus.MustNewConstMetric( + prometheus.NewDesc( + prometheus.BuildFQName("gateway", globalGatewayName, "requests"), + "Total number of requests made to "+globalGatewayName+" by current MinIO Gateway", + []string{"method"}, nil), + prometheus.CounterValue, + float64(s.Put.Load()), + http.MethodPut, + ) + ch <- prometheus.MustNewConstMetric( + prometheus.NewDesc( + prometheus.BuildFQName("gateway", globalGatewayName, "requests"), + "Total number of requests made to "+globalGatewayName+" by current MinIO Gateway", + []string{"method"}, nil), + prometheus.CounterValue, + float64(s.Post.Load()), + http.MethodPost, + ) } // collects cache metrics for MinIO server in Prometheus specific format diff --git a/docs/metrics/prometheus/README.md b/docs/metrics/prometheus/README.md index a9aadfc4c..fcbdb4346 100644 --- a/docs/metrics/prometheus/README.md +++ b/docs/metrics/prometheus/README.md @@ -151,8 +151,8 @@ MinIO Gateway instances enabled with Disk-Caching expose caching related metrics MinIO Gateway instance exposes metrics related to Gateway communication with the cloud backend (S3, Azure & GCS Gateway). -- `gateway__requests`: Total number of GET & HEAD requests made to cloud backend. This metrics has a label `method` that identifies GET & HEAD Requests. -- `gateway__bytes_sent`: Total number of bytes sent to cloud backend (in GET & HEAD Requests). +- `gateway__requests`: Total number of requests made to cloud backend. This metrics has a label `method` that identifies GET, HEAD, PUT and POST Requests. +- `gateway__bytes_sent`: Total number of bytes sent to cloud backend (in PUT & POST Requests). - `gateway__bytes_received`: Total number of bytes received from cloud backend (in GET & HEAD Requests). Note that this is currently only support for Azure, S3 and GCS Gateway.