diff --git a/jsonrpc/metrics/metrics_xlayer.go b/jsonrpc/metrics/metrics_xlayer.go index 89701fc1b4..474fccfe5c 100644 --- a/jsonrpc/metrics/metrics_xlayer.go +++ b/jsonrpc/metrics/metrics_xlayer.go @@ -16,6 +16,7 @@ var ( requestAuthCountName = requestPrefix + "auth_count" requestAuthErrorCountName = requestPrefix + "auth_error_count" requestRelayFailCountName = requestPrefix + "relay_fail_count" + requestBatchSizeName = requestPrefix + "batch_size" wsRequestPrefix = prefix + "ws_request_" requestWsMethodName = wsRequestPrefix + "method" @@ -38,6 +39,10 @@ var ( Name: lastRawGasPriceName, Help: "[JSONRPC] raw gas price", }, + { + Name: requestBatchSizeName, + Help: "[JSONRPC] batch request size", + }, } histogramVecs = []metrics.HistogramVecOpts{ @@ -192,3 +197,8 @@ func RequestAuthErrorCount(tp RequestAuthErrorType) { func RequestRelayFailCount(method string) { metrics.CounterVecInc(requestRelayFailCountName, method) } + +// RequestBatchSize increments the batch requests count +func RequestBatchSize(batchSize int) { + metrics.GaugeSet(requestBatchSizeName, float64(batchSize)) +} diff --git a/jsonrpc/server.go b/jsonrpc/server.go index 891e4d918b..faa38f2a10 100644 --- a/jsonrpc/server.go +++ b/jsonrpc/server.go @@ -369,7 +369,7 @@ func (s *Server) handleBatchRequest(httpRequest *http.Request, w http.ResponseWr } responses := make([]types.Response, 0, len(requests)) - + var methods string for _, request := range requests { if !methodRateLimitAllow(request.Method) { responses = append(responses, types.NewResponse(request, nil, types.NewRPCError(types.InvalidParamsErrorCode, "server is too busy"))) @@ -384,7 +384,10 @@ func (s *Server) handleBatchRequest(httpRequest *http.Request, w http.ResponseWr } responses = append(responses, response) metrics.RequestMethodDuration(request.Method, st) + methods += request.Method + "," } + metrics.RequestBatchSize(len(responses)) + log.Infof("Batch request handled: %s total: %d", methods, len(responses)) respBytes, _ := json.Marshal(responses) _, err = w.Write(respBytes)