@@ -64,7 +64,8 @@ type gatewayHandler struct {
64
64
config GatewayConfig
65
65
api coreiface.CoreAPI
66
66
67
- unixfsGetMetric * prometheus.SummaryVec
67
+ unixfsGetMetric * prometheus.SummaryVec
68
+ unixfsGetHistMetric * prometheus.HistogramVec
68
69
}
69
70
70
71
// StatusResponseWriter enables us to override HTTP Status Code passed to
@@ -104,10 +105,29 @@ func newGatewayHandler(c GatewayConfig, api coreiface.CoreAPI) *gatewayHandler {
104
105
}
105
106
}
106
107
108
+ unixfsGetHistMetric := prometheus .NewHistogramVec (
109
+ prometheus.HistogramOpts {
110
+ Namespace : "ipfs" ,
111
+ Subsystem : "http" ,
112
+ Name : "unixfs_get_latency_hist_seconds" ,
113
+ Help : "The time till the first block is received when 'getting' a file from the gateway." ,
114
+ Buckets : []float64 {0.1 , 0.5 , 1 , 2 , 3 , 5 , 8 , 13 },
115
+ },
116
+ []string {"gateway" },
117
+ )
118
+ if err := prometheus .Register (unixfsGetHistMetric ); err != nil {
119
+ if are , ok := err .(prometheus.AlreadyRegisteredError ); ok {
120
+ unixfsGetHistMetric = are .ExistingCollector .(* prometheus.HistogramVec )
121
+ } else {
122
+ log .Errorf ("failed to register unixfsGetMetric: %v" , err )
123
+ }
124
+ }
125
+
107
126
i := & gatewayHandler {
108
- config : c ,
109
- api : api ,
110
- unixfsGetMetric : unixfsGetMetric ,
127
+ config : c ,
128
+ api : api ,
129
+ unixfsGetMetric : unixfsGetMetric ,
130
+ unixfsGetHistMetric : unixfsGetHistMetric ,
111
131
}
112
132
return i
113
133
}
@@ -292,7 +312,9 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
292
312
return
293
313
}
294
314
295
- i .unixfsGetMetric .WithLabelValues (parsedPath .Namespace ()).Observe (time .Since (begin ).Seconds ())
315
+ timeToGetFirstNode := time .Since (begin ).Seconds ()
316
+ i .unixfsGetMetric .WithLabelValues (parsedPath .Namespace ()).Observe (timeToGetFirstNode )
317
+ i .unixfsGetHistMetric .WithLabelValues (parsedPath .Namespace ()).Observe (timeToGetFirstNode )
296
318
297
319
defer dr .Close ()
298
320
0 commit comments