Added Metrics for number of open RPC connections[#3781] (#3831)

* Added Metrics for number of open RPC connections - besu_rpc_active_http_connection_count, besu_rpc_active_ws_connection_count

Signed-off-by: Sharad Gulati <sharad.develop@gmail.com>

Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
Co-authored-by: Diego López León <dieguitoll@gmail.com>
Co-authored-by: Danno Ferrin <danno.ferrin@gmail.com>
Co-authored-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Co-authored-by: Justin Florentine <justin+github@florentine.us>
Co-authored-by: garyschulte <garyschulte@gmail.com>
Co-authored-by: Daniel Lehrner <daniel.lehrner@consensys.net>
Co-authored-by: Jason Frame <jasonwframe@gmail.com>
Co-authored-by: Jason Frame <jason.frame@consensys.net>
Co-authored-by: Antoine Toulme <antoine@lunar-ocean.com>
pull/3922/head
sharad-develop 3 years ago committed by GitHub
parent 501ba644e6
commit 154dc86522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
  2. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpService.java
  3. 17
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketService.java
  4. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketHostAllowlistTest.java
  5. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceLoginTest.java
  6. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceTest.java

@ -767,7 +767,8 @@ public class RunnerBuilder {
privacyParameters,
protocolSchedule,
blockchainQueries,
DefaultAuthenticationService.create(vertx, webSocketConfiguration)));
DefaultAuthenticationService.create(vertx, webSocketConfiguration),
metricsSystem));
createPrivateTransactionObserver(subscriptionManager, privacyParameters);
}
@ -1105,7 +1106,8 @@ public class RunnerBuilder {
final PrivacyParameters privacyParameters,
final ProtocolSchedule protocolSchedule,
final BlockchainQueries blockchainQueries,
final Optional<AuthenticationService> authenticationService) {
final Optional<AuthenticationService> authenticationService,
final ObservableMetricsSystem metricsSystem) {
final WebSocketMethodsFactory websocketMethodsFactory =
new WebSocketMethodsFactory(subscriptionManager, jsonRpcMethods);
@ -1143,7 +1145,7 @@ public class RunnerBuilder {
webSocketConfiguration.getTimeoutSec());
return new WebSocketService(
vertx, configuration, websocketMessageHandler, authenticationService);
vertx, configuration, websocketMessageHandler, authenticationService, metricsSystem);
}
private Optional<MetricsService> createMetricsService(

@ -184,6 +184,13 @@ public class JsonRpcHttpService {
"request_time",
"Time taken to process a JSON-RPC request",
"methodName");
metricsSystem.createIntegerGauge(
BesuMetricCategory.RPC,
"active_http_connection_count",
"Total no of active rpc http connections",
activeConnectionsCount::intValue);
validateConfig(config);
this.config = config;
this.vertx = vertx;

@ -20,6 +20,8 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.authentication.AuthenticationSe
import org.hyperledger.besu.ethereum.api.jsonrpc.authentication.AuthenticationUtils;
import org.hyperledger.besu.ethereum.api.jsonrpc.authentication.DefaultAuthenticationService;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionManager;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import java.net.InetSocketAddress;
import java.util.Optional;
@ -67,24 +69,33 @@ public class WebSocketService {
public WebSocketService(
final Vertx vertx,
final WebSocketConfiguration configuration,
final WebSocketMessageHandler websocketMessageHandler) {
final WebSocketMessageHandler websocketMessageHandler,
final MetricsSystem metricsSystem) {
this(
vertx,
configuration,
websocketMessageHandler,
DefaultAuthenticationService.create(vertx, configuration));
DefaultAuthenticationService.create(vertx, configuration),
metricsSystem);
}
public WebSocketService(
final Vertx vertx,
final WebSocketConfiguration configuration,
final WebSocketMessageHandler websocketMessageHandler,
final Optional<AuthenticationService> authenticationService) {
final Optional<AuthenticationService> authenticationService,
final MetricsSystem metricsSystem) {
this.vertx = vertx;
this.configuration = configuration;
this.websocketMessageHandler = websocketMessageHandler;
this.authenticationService = authenticationService;
this.maxActiveConnections = configuration.getMaxActiveConnections();
metricsSystem.createIntegerGauge(
BesuMetricCategory.RPC,
"active_ws_connection_count",
"Total no of active rpc ws connections",
activeConnectionsCount::intValue);
}
public CompletableFuture<?> start() {

@ -85,7 +85,8 @@ public class WebSocketHostAllowlistTest {
TimeoutOptions.defaultOptions().getTimeoutSeconds()));
websocketService =
new WebSocketService(vertx, webSocketConfiguration, webSocketMessageHandlerSpy);
new WebSocketService(
vertx, webSocketConfiguration, webSocketMessageHandlerSpy, new NoOpMetricsSystem());
websocketService.start().join();
final InetSocketAddress inetSocketAddress = websocketService.socketAddress();

@ -201,7 +201,8 @@ public class WebSocketServiceLoginTest {
TimeoutOptions.defaultOptions().getTimeoutSeconds()));
websocketService =
new WebSocketService(vertx, websocketConfiguration, webSocketMessageHandlerSpy);
new WebSocketService(
vertx, websocketConfiguration, webSocketMessageHandlerSpy, new NoOpMetricsSystem());
websocketService.start().join();
jwtAuth = websocketService.authenticationService.get().getJwtAuthProvider();

@ -88,7 +88,8 @@ public class WebSocketServiceTest {
TimeoutOptions.defaultOptions().getTimeoutSeconds()));
websocketService =
new WebSocketService(vertx, websocketConfiguration, webSocketMessageHandlerSpy);
new WebSocketService(
vertx, websocketConfiguration, webSocketMessageHandlerSpy, new NoOpMetricsSystem());
websocketService.start().join();
websocketConfiguration.setPort(websocketService.socketAddress().getPort());

Loading…
Cancel
Save