88
99var durationHistogramBuckets = []float64 {0.05 , 0.1 , 0.25 , 0.5 , 1 , 2 , 5 , 10 , 30 , 60 , 120 , 240 , 480 , 960 , 1920 }
1010
11+ var blockSizesHistogramBuckets = []float64 {1 , 128 << 10 , 256 << 10 , 512 << 10 , 1024 << 10 , 2048 << 10 , 4092 << 10 }
12+
1113type ctxKeyT string
1214
1315var ctxKey ctxKeyT = ctxKeyT (imetrics .CtxScopeKey )
@@ -68,6 +70,10 @@ func requestTime(ctx context.Context) imetrics.Histogram {
6870 return imetrics .NewCtx (ctx , "httpnet_request_duration_seconds" , "Histogram of request durations" ).Histogram (durationHistogramBuckets )
6971}
7072
73+ func responseSize (ctx context.Context ) imetrics.Histogram {
74+ return imetrics .NewCtx (ctx , "httpnet_response_bytes" , "Histogram of http response sizes" ).Histogram (blockSizesHistogramBuckets )
75+ }
76+
7177type metrics struct {
7278 RequestsInFlight imetrics.Gauge
7379 RequestsTotal imetrics.Counter
@@ -83,6 +89,7 @@ type metrics struct {
8389 StatusInternalServerError imetrics.Counter
8490 StatusOthers imetrics.Counter
8591 RequestTime imetrics.Histogram
92+ ResponseSize imetrics.Histogram
8693}
8794
8895func newMetrics () * metrics {
@@ -103,6 +110,7 @@ func newMetrics() *metrics {
103110 StatusInternalServerError : statusInternalServerError (ctx ),
104111 StatusOthers : statusOthers (ctx ),
105112 RequestTime : requestTime (ctx ),
113+ ResponseSize : responseSize (ctx ),
106114 }
107115}
108116
0 commit comments