io.vertx.core.spi.metrics.ClientMetrics Java Examples

The following examples show how to use io.vertx.core.spi.metrics.ClientMetrics. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricsTest.java    From vertx-dropwizard-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void testClientMetricsLifecycle() {
  VertxMetrics spi = ((VertxInternal) vertx).metricsSPI();
  SocketAddress address = SocketAddress.inetSocketAddress(8080, "localhost");
  ClientMetrics[] metrics = new ClientMetrics[2];
  for (int i = 0;i < metrics.length;i++) {
    metrics[i] = spi.createClientMetrics(address, "backend", "acme");
  }
  JsonObject snapshot = metricsService.getMetricsSnapshot("vertx.backend.clients.acme.localhost:8080");
  assertTrue(snapshot.size() > 0);
  metrics[0].close();
  snapshot = metricsService.getMetricsSnapshot("vertx.backend.clients.acme.localhost:8080");
  assertTrue(snapshot.size() > 0);
  metrics[1].close();
  snapshot = metricsService.getMetricsSnapshot("vertx.backend.clients.acme.localhost:8080");
  assertTrue(snapshot.size() == 0);
}
 
Example #2
Source File: MetricsTest.java    From vertx-dropwizard-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void testClientMetricsReporting() {
  SocketAddress address = SocketAddress.inetSocketAddress(8080, "localhost");
  ClientMetrics metrics = ((VertxInternal) vertx).metricsSPI().createClientMetrics(address, "backend", null);

  // Queue
  Object queueMetric = metrics.enqueueRequest();
  JsonObject snapshot = metricsService.getMetricsSnapshot("vertx.backend.clients.localhost:8080");
  assertEquals(1, (int)snapshot.getJsonObject("vertx.backend.clients.localhost:8080.queue-size").getInteger("count"));
  metrics.dequeueRequest(queueMetric);
  snapshot = metricsService.getMetricsSnapshot("vertx.backend.clients.localhost:8080");
  assertEquals(0, (int)snapshot.getJsonObject("vertx.backend.clients.localhost:8080.queue-size").getInteger("count"));
  assertEquals(1, (int)snapshot.getJsonObject("vertx.backend.clients.localhost:8080.queue-delay").getInteger("count"));

  // Request
  Object request = new Object();
  Object response = new Object();
  Object requestMetric = metrics.requestBegin("some-uri", request);
  metrics.requestEnd(requestMetric);
  metrics.responseBegin(requestMetric, response);
  snapshot = metricsService.getMetricsSnapshot("vertx.backend.clients.localhost:8080");
  assertEquals(0, (int)snapshot.getJsonObject("vertx.backend.clients.localhost:8080.requests").getInteger("count"));
  metrics.responseEnd(requestMetric, response);
  snapshot = metricsService.getMetricsSnapshot("vertx.backend.clients.localhost:8080");
  assertEquals(1, (int)snapshot.getJsonObject("vertx.backend.clients.localhost:8080.requests").getInteger("count"));
}
 
Example #3
Source File: VertxMetricsImpl.java    From vertx-dropwizard-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized ClientMetrics<?, ?, ?, ?> createClientMetrics(SocketAddress remoteAddress, String type, String namespace) {
  String baseName;
  if (namespace != null && namespace.length() > 0) {
    baseName = MetricRegistry.name(nameOf(type, "clients", namespace, remoteAddress.toString()));
  } else {
    baseName = MetricRegistry.name(nameOf(type, "clients", remoteAddress.toString()));
  }
  return clientMetrics.compute(baseName, (key, prev) -> {
    if (prev == null) {
      return new DropwizardClientMetrics<>(this, registry, baseName, 1);
    } else {
      return prev.inc();
    }
  });
}
 
Example #4
Source File: PgPoolImpl.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
public static PgPoolImpl create(ContextInternal context, boolean closeVertx, PgConnectOptions connectOptions, PoolOptions poolOptions) {
  QueryTracer tracer = context.tracer() == null ? null : new QueryTracer(context.tracer(), connectOptions);
  VertxMetrics vertxMetrics = context.owner().metricsSPI();
  ClientMetrics metrics = vertxMetrics != null ? vertxMetrics.createClientMetrics(connectOptions.getSocketAddress(), "sql", connectOptions.getMetricsName()) : null;
  PgPoolImpl pool = new PgPoolImpl(context, new PgConnectionFactory(context.owner(), context, connectOptions), tracer, metrics, poolOptions);
  CloseFuture closeFuture = pool.closeFuture();
  if (closeVertx) {
    closeFuture.onComplete(ar -> context.owner().close());
  } else {
    context.addCloseHook(closeFuture);
  }
  return pool;
}
 
Example #5
Source File: HttpClientMetricsImpl.java    From vertx-dropwizard-metrics with Apache License 2.0 5 votes vote down vote up
@Override
public ClientMetrics<HttpClientRequestMetric, Timer.Context, HttpClientRequest, HttpClientResponse> createEndpointMetrics(SocketAddress remoteAddress, int maxPoolSize) {
  String name = remoteAddress.toString();
  if (endpointMatcher.matches(name) != null) {
    return new EndpointMetrics(clientReporter, name, uriMatcher);
  } else {
    return null;
  }
}
 
Example #6
Source File: MySQLPoolImpl.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
public static MySQLPoolImpl create(ContextInternal context, boolean closeVertx, MySQLConnectOptions connectOptions, PoolOptions poolOptions) {
  QueryTracer tracer = context.tracer() == null ? null : new QueryTracer(context.tracer(), connectOptions);
  VertxMetrics vertxMetrics = context.owner().metricsSPI();
  ClientMetrics metrics = vertxMetrics != null ? vertxMetrics.createClientMetrics(connectOptions.getSocketAddress(), "sql", connectOptions.getMetricsName()) : null;
  MySQLPoolImpl pool = new MySQLPoolImpl(context, new MySQLConnectionFactory(context, connectOptions), tracer, metrics, poolOptions);
  CloseFuture closeFuture = pool.closeFuture();
  if (closeVertx) {
    closeFuture.onComplete(ar -> context.owner().close());
  } else {
    context.addCloseHook(closeFuture);
  }
  return pool;
}
 
Example #7
Source File: MySQLConnectionImpl.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
private static void connect(MySQLConnectionFactory client, ContextInternal ctx, QueryTracer tracer, ClientMetrics metrics, Promise<MySQLConnection> promise) {
  client.connect()
    .map(conn -> {
      MySQLConnectionImpl mySQLConnection = new MySQLConnectionImpl(client, ctx, conn, tracer, metrics);
      conn.init(mySQLConnection);
      return (MySQLConnection) mySQLConnection;
    }).onComplete(promise);
}
 
Example #8
Source File: MetricsTestBase.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testClosePool(TestContext ctx) {
  AtomicInteger closeCount = new AtomicInteger();
  metrics = new ClientMetrics() {
    @Override
    public void close() {
      closeCount.incrementAndGet();
    }
  };
  Pool pool = createPool(vertx);
  ctx.assertEquals(0, closeCount.get());
  pool.close(ctx.asyncAssertSuccess(v -> {
    ctx.assertEquals(1, closeCount.get());
  }));
}
 
Example #9
Source File: MetricsTestBase.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(
    new MetricsOptions().setEnabled(true).setFactory(tracingOptions -> new VertxMetrics() {
      @Override
      public ClientMetrics<?, ?, ?, ?> createClientMetrics(SocketAddress remoteAddress, String type, String namespace) {
        return metrics;
      }
    }))
  );
}
 
Example #10
Source File: PoolBase.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
public PoolBase(ContextInternal context, ConnectionFactory factory, QueryTracer tracer, ClientMetrics metrics, PoolOptions poolOptions) {
  super(tracer, metrics);
  this.vertx = context.owner();
  this.factory = factory;
  this.pool = new ConnectionPool(factory, context, poolOptions.getMaxSize(), poolOptions.getMaxWaitQueueSize());
  this.closeFuture = new CloseFuture(this);
}
 
Example #11
Source File: QueryExecutor.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
public QueryExecutor(QueryTracer tracer,
                     ClientMetrics metrics,
                     Function<T, R> factory,
                     Collector<Row, ?, T> collector) {
  this.tracer = tracer;
  this.metrics = metrics;
  this.factory = factory;
  this.collector = collector;
}
 
Example #12
Source File: QueryResultBuilder.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
QueryResultBuilder(Function<T, R> factory, QueryTracer tracer, Object tracingPayload, ClientMetrics metrics, Object metric, Promise<L> handler) {
  this.factory = factory;
  this.context = (ContextInternal) handler.future().context();
  this.tracer = tracer;
  this.tracingPayload = tracingPayload;
  this.metrics = metrics;
  this.metric = metric;
  this.handler = handler;
}
 
Example #13
Source File: DB2PoolImpl.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
public static DB2PoolImpl create(ContextInternal context, boolean closeVertx, DB2ConnectOptions connectOptions,
                                 PoolOptions poolOptions) {
  QueryTracer tracer = context.tracer() == null ? null : new QueryTracer(context.tracer(), connectOptions);
  VertxMetrics vertxMetrics = context.owner().metricsSPI();
  ClientMetrics metrics = vertxMetrics != null ? vertxMetrics.createClientMetrics(connectOptions.getSocketAddress(), "sql", connectOptions.getMetricsName()) : null;
  DB2PoolImpl pool = new DB2PoolImpl(context, poolOptions, new DB2ConnectionFactory(context, connectOptions), tracer, metrics);
  CloseFuture closeFuture = pool.closeFuture();
  if (closeVertx) {
    closeFuture.onComplete(ar -> context.owner().close());
  } else {
    context.addCloseHook(closeFuture);
  }
  return pool;
}
 
Example #14
Source File: MSSQLPoolImpl.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
public static MSSQLPoolImpl create(ContextInternal context, boolean closeVertx, MSSQLConnectOptions connectOptions, PoolOptions poolOptions) {
  QueryTracer tracer = context.tracer() == null ? null : new QueryTracer(context.tracer(), connectOptions);
  VertxMetrics vertxMetrics = context.owner().metricsSPI();
  ClientMetrics metrics = vertxMetrics != null ? vertxMetrics.createClientMetrics(connectOptions.getSocketAddress(), "sql", connectOptions.getMetricsName()) : null;
  MSSQLPoolImpl pool = new MSSQLPoolImpl(context, new MSSQLConnectionFactory(context, connectOptions), tracer, metrics, poolOptions);
  CloseFuture closeFuture = pool.closeFuture();
  if (closeVertx) {
    closeFuture.onComplete(ar -> context.owner().close());
  } else {
    context.addCloseHook(closeFuture);
  }
  return pool;
}
 
Example #15
Source File: PreparedStatementImpl.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
private PreparedStatementImpl(Connection conn, QueryTracer tracer, ClientMetrics metrics, ContextInternal context, io.vertx.sqlclient.impl.PreparedStatement ps, boolean autoCommit) {
  this.conn = conn;
  this.tracer = tracer;
  this.metrics = metrics;
  this.context = context;
  this.ps = ps;
  this.autoCommit = autoCommit;
}
 
Example #16
Source File: MySQLConnectionImpl.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
public MySQLConnectionImpl(MySQLConnectionFactory factory, ContextInternal context, Connection conn, QueryTracer tracer, ClientMetrics metrics) {
  super(context, conn, tracer, metrics);

  this.factory = factory;
}
 
Example #17
Source File: PgConnectionImpl.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
PgConnectionImpl(PgConnectionFactory factory, ContextInternal context, Connection conn, QueryTracer tracer, ClientMetrics metrics) {
  super(context, conn, tracer, metrics);

  this.factory = factory;
}
 
Example #18
Source File: PgPoolImpl.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
private PgPoolImpl(ContextInternal context, PgConnectionFactory factory, QueryTracer tracer, ClientMetrics metrics, PoolOptions poolOptions) {
  super(context, factory, tracer, metrics, poolOptions);
  this.factory = factory;
}
 
Example #19
Source File: DB2ConnectionImpl.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
public DB2ConnectionImpl(DB2ConnectionFactory factory, ContextInternal context, Connection conn, QueryTracer tracer, ClientMetrics metrics) {
  super(context, conn, tracer, metrics);
}
 
Example #20
Source File: HttpClientMetricsImpl.java    From vertx-dropwizard-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public void endpointDisconnected(ClientMetrics<HttpClientRequestMetric, Timer.Context, ?, ?> endpointMetric) {
  if (endpointMetric instanceof EndpointMetrics) {
    ((EndpointMetrics)endpointMetric).openConnections.dec();
  }
}
 
Example #21
Source File: HttpClientMetricsImpl.java    From vertx-dropwizard-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public void endpointConnected(ClientMetrics<HttpClientRequestMetric, Timer.Context, ?, ?> endpointMetric) {
  if (endpointMetric instanceof EndpointMetrics) {
    ((EndpointMetrics)endpointMetric).openConnections.inc();
  }
}
 
Example #22
Source File: MySQLPoolImpl.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
private MySQLPoolImpl(ContextInternal context, MySQLConnectionFactory factory, QueryTracer tracer, ClientMetrics metrics, PoolOptions poolOptions) {
  super(context, factory, tracer, metrics, poolOptions);
  this.factory = factory;
}
 
Example #23
Source File: DB2PoolImpl.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
private DB2PoolImpl(ContextInternal context, PoolOptions poolOptions, DB2ConnectionFactory factory, QueryTracer tracer, ClientMetrics metrics) {
  super(context, factory, tracer, metrics, poolOptions);
  this.factory = factory;
}
 
Example #24
Source File: MSSQLPoolImpl.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
private MSSQLPoolImpl(ContextInternal context, MSSQLConnectionFactory factory, QueryTracer tracer, ClientMetrics metrics, PoolOptions poolOptions) {
  super(context, factory, tracer, metrics, poolOptions);
  this.connectionFactory = factory;
}
 
Example #25
Source File: MSSQLConnectionImpl.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
public MSSQLConnectionImpl(MSSQLConnectionFactory factory, ContextInternal context, Connection conn, QueryTracer tracer, ClientMetrics metrics) {
  super(context, conn, tracer, metrics);
  this.factory = factory;
}
 
Example #26
Source File: SqlConnectionImpl.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
public SqlConnectionImpl(ContextInternal context, Connection conn, QueryTracer tracer, ClientMetrics metrics) {
  super(context, conn, tracer, metrics);
}
 
Example #27
Source File: SqlConnectionBase.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
protected SqlConnectionBase(ContextInternal context, Connection conn, QueryTracer tracer, ClientMetrics metrics) {
  super(tracer, metrics);
  this.context = context;
  this.conn = conn;
}
 
Example #28
Source File: QueryExecutor.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
ClientMetrics metrics() {
  return metrics;
}
 
Example #29
Source File: SqlClientBase.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
public SqlClientBase(QueryTracer tracer, ClientMetrics metrics) {
  this.tracer = tracer;
  this.metrics = metrics;
}
 
Example #30
Source File: PreparedStatementImpl.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
static PreparedStatement create(Connection conn, QueryTracer tracer, ClientMetrics metrics, ContextInternal context, io.vertx.sqlclient.impl.PreparedStatement ps, boolean autoCommit) {
  return new PreparedStatementImpl(conn, tracer, metrics, context, ps, autoCommit);
}