fix: gateway_s3_bytes_sent metric for all API methods (#9242)

Co-authored-by: Harshavardhana <harsha@minio.io>
master
poornas 5 years ago committed by GitHub
parent 95e89f1712
commit 336460f67e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      cmd/gateway-common.go
  2. 6
      cmd/gateway-metrics.go
  3. 18
      cmd/metrics.go
  4. 4
      docs/metrics/prometheus/README.md

@ -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))
}
}

@ -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)
}
}

@ -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

@ -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_<gateway_type>_requests`: Total number of GET & HEAD requests made to cloud backend. This metrics has a label `method` that identifies GET & HEAD Requests.
- `gateway_<gateway_type>_bytes_sent`: Total number of bytes sent to cloud backend (in GET & HEAD Requests).
- `gateway_<gateway_type>_requests`: Total number of requests made to cloud backend. This metrics has a label `method` that identifies GET, HEAD, PUT and POST Requests.
- `gateway_<gateway_type>_bytes_sent`: Total number of bytes sent to cloud backend (in PUT & POST Requests).
- `gateway_<gateway_type>_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.

Loading…
Cancel
Save