Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
New metrics for tracking request and response size
Browse files Browse the repository at this point in the history
  • Loading branch information
eitu5ami committed May 13, 2022
1 parent 56a24e2 commit 3dc39fe
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion pkg/rpcgateway/rpcgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type RPCGateway struct {

server *http.Server
metricRequestsProcessed *prometheus.CounterVec
metricRequestSize *prometheus.HistogramVec
metricResponseSize *prometheus.HistogramVec
}

func (r *RPCGateway) ServeHTTP(w http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -103,9 +105,45 @@ func NewRPCGateway(config RPCGatewayConfig) *RPCGateway {
"code",
"method",
}),
metricRequestSize: promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "zeroex_rpc_gateway_request_size_bytes",
Help: "Histogram of HTTP request sizes",
Buckets: []float64{
100,
250,
500,
1000,
1500,
2000,
},
}, []string{
"code",
"method",
},
),
metricResponseSize: promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "zeroex_rpc_gateway_response_size_bytes",
Help: "Histogram of HTTP responses sizes",
Buckets: []float64{
100,
250,
500,
1000,
1500,
2000,
},
}, []string{
"code",
"method",
},
),
}

handler := promhttp.InstrumentHandlerCounter(gateway.metricRequestsProcessed, httpFailoverProxy)
handler := promhttp.InstrumentHandlerCounter(gateway.metricRequestsProcessed,
promhttp.InstrumentHandlerRequestSize(gateway.metricRequestSize,
promhttp.InstrumentHandlerResponseSize(gateway.metricResponseSize, httpFailoverProxy)))

r.PathPrefix("/").Handler(handler)
r.PathPrefix("").Handler(handler)
Expand Down

0 comments on commit 3dc39fe

Please sign in to comment.