diff --git a/bitswap/network/httpnet/metrics.go b/bitswap/network/httpnet/metrics.go index 925d8f7dd..7caac6a95 100644 --- a/bitswap/network/httpnet/metrics.go +++ b/bitswap/network/httpnet/metrics.go @@ -8,6 +8,8 @@ import ( var durationHistogramBuckets = []float64{0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 30, 60, 120, 240, 480, 960, 1920} +var blockSizesHistogramBuckets = []float64{1, 128 << 10, 256 << 10, 512 << 10, 1024 << 10, 2048 << 10, 4092 << 10} + type ctxKeyT string var ctxKey ctxKeyT = ctxKeyT(imetrics.CtxScopeKey) @@ -68,6 +70,10 @@ func requestTime(ctx context.Context) imetrics.Histogram { return imetrics.NewCtx(ctx, "httpnet_request_duration_seconds", "Histogram of request durations").Histogram(durationHistogramBuckets) } +func responseSize(ctx context.Context) imetrics.Histogram { + return imetrics.NewCtx(ctx, "httpnet_response_bytes", "Histogram of http response sizes").Histogram(blockSizesHistogramBuckets) +} + type metrics struct { RequestsInFlight imetrics.Gauge RequestsTotal imetrics.Counter @@ -83,6 +89,7 @@ type metrics struct { StatusInternalServerError imetrics.Counter StatusOthers imetrics.Counter RequestTime imetrics.Histogram + ResponseSize imetrics.Histogram } func newMetrics() *metrics { @@ -103,6 +110,7 @@ func newMetrics() *metrics { StatusInternalServerError: statusInternalServerError(ctx), StatusOthers: statusOthers(ctx), RequestTime: requestTime(ctx), + ResponseSize: responseSize(ctx), } } diff --git a/bitswap/network/httpnet/msg_sender.go b/bitswap/network/httpnet/msg_sender.go index 503db41bb..adc0139a2 100644 --- a/bitswap/network/httpnet/msg_sender.go +++ b/bitswap/network/httpnet/msg_sender.go @@ -254,7 +254,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm } } reqDuration := time.Since(reqStart) - + sender.ht.metrics.ResponseSize.Observe(float64(len(body))) sender.ht.metrics.RequestsInFlight.Dec() sender.ht.metrics.RequestTime.Observe(float64(reqDuration) / float64(time.Second)) sender.ht.metrics.updateStatusCounter(resp.StatusCode)