use of io.vertx.core.metrics.MetricsOptions in project vertx-micrometer-metrics by vert-x3.
the class VertxMetricsFactoryImpl method metrics.
@Override
public VertxMetrics metrics(Vertx vertx, VertxOptions vertxOptions) {
MetricsOptions metricsOptions = vertxOptions.getMetricsOptions();
MicrometerMetricsOptions options;
if (metricsOptions instanceof MicrometerMetricsOptions) {
options = (MicrometerMetricsOptions) metricsOptions;
} else {
options = new MicrometerMetricsOptions(metricsOptions.toJson());
}
BackendRegistry backendRegistry = BackendRegistries.setupBackend(vertx, options);
return new VertxMetricsImpl(options, backendRegistry);
}
use of io.vertx.core.metrics.MetricsOptions in project incubator-servicecomb-java-chassis by apache.
the class TestDefaultVertxMetricsFactory method metrics.
@SuppressWarnings("deprecation")
@Test
public void metrics() {
MetricsOptions metricsOptions = factory.newOptions();
options.setMetricsOptions(metricsOptions);
VertxMetrics vertxMetrics = factory.metrics(options);
Assertions.assertSame(factory, metricsOptions.getFactory());
Assertions.assertTrue(metricsOptions.isEnabled());
Assertions.assertSame(factory.getVertxMetrics(), vertxMetrics);
Assertions.assertTrue(vertxMetrics.isMetricsEnabled());
}
use of io.vertx.core.metrics.MetricsOptions in project vertx-micrometer-metrics by vert-x3.
the class MetricsServiceImplTest method shouldGetJvmMetricsInSnapshot.
@Test
public void shouldGetJvmMetricsInSnapshot(TestContext ctx) {
MetricsOptions metricsOptions = new MicrometerMetricsOptions().setJvmMetricsEnabled(true).setMicrometerRegistry(new SimpleMeterRegistry()).setRegistryName(registryName).setEnabled(true);
VertxOptions vertxOptions = new VertxOptions().setMetricsOptions(metricsOptions);
Vertx vertx = Vertx.vertx(vertxOptions).exceptionHandler(ctx.exceptionHandler());
JsonObject snapshot = MetricsService.create(vertx).getMetricsSnapshot("jvm");
assertFalse(snapshot.isEmpty());
vertx.close(ctx.asyncAssertSuccess());
}
use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse-vertx.
the class MetricsContextTest method testHttpServerWebSocket.
private void testHttpServerWebSocket(Function<Vertx, Context> contextFactory) throws Exception {
AtomicReference<Thread> expectedThread = new AtomicReference<>();
AtomicReference<Context> expectedContext = new AtomicReference<>();
AtomicBoolean webSocketConnected = new AtomicBoolean();
AtomicBoolean webSocketDisconnected = new AtomicBoolean();
AtomicBoolean socketConnectedCalled = new AtomicBoolean();
AtomicBoolean socketDisconnectedCalled = new AtomicBoolean();
AtomicBoolean bytesReadCalled = new AtomicBoolean();
AtomicBoolean bytesWrittenCalled = new AtomicBoolean();
AtomicBoolean closeCalled = new AtomicBoolean();
AtomicInteger httpLifecycle = new AtomicInteger();
VertxMetricsFactory factory = (options) -> new DummyVertxMetrics() {
@Override
public HttpServerMetrics createHttpServerMetrics(HttpServerOptions options, SocketAddress localAddress) {
return new DummyHttpServerMetrics() {
@Override
public Void requestBegin(Void socketMetric, HttpRequest request) {
assertEquals(0, httpLifecycle.getAndIncrement());
return null;
}
@Override
public void requestEnd(Void requestMetric, HttpRequest request, long bytesRead) {
assertEquals(1, httpLifecycle.getAndIncrement());
}
@Override
public void responseBegin(Void requestMetric, HttpResponse response) {
assertEquals(2, httpLifecycle.getAndIncrement());
}
@Override
public void responseEnd(Void requestMetric, HttpResponse response, long bytesWritten) {
assertEquals(3, httpLifecycle.getAndIncrement());
}
@Override
public Void connected(Void socketMetric, Void requestMetric, ServerWebSocket serverWebSocket) {
assertEquals(2, httpLifecycle.get());
webSocketConnected.set(true);
return null;
}
@Override
public void disconnected(Void serverWebSocketMetric) {
assertEquals(4, httpLifecycle.get());
webSocketDisconnected.set(true);
}
@Override
public Void connected(SocketAddress remoteAddress, String remoteName) {
socketConnectedCalled.set(true);
return null;
}
@Override
public void disconnected(Void socketMetric, SocketAddress remoteAddress) {
socketDisconnectedCalled.set(true);
}
@Override
public void bytesRead(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
bytesReadCalled.set(true);
}
@Override
public void bytesWritten(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
bytesWrittenCalled.set(true);
}
@Override
public void close() {
closeCalled.set(true);
}
};
}
};
CountDownLatch latch = new CountDownLatch(1);
Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
Context ctx = contextFactory.apply(vertx);
ctx.runOnContext(v1 -> {
HttpServer server = vertx.createHttpServer().webSocketHandler(ws -> {
ws.handler(buf -> {
ws.write(Buffer.buffer("bye"));
});
});
server.listen(8080, "localhost", onSuccess(s -> {
expectedThread.set(Thread.currentThread());
expectedContext.set(Vertx.currentContext());
latch.countDown();
}));
});
awaitLatch(latch);
HttpClient client = vertx.createHttpClient();
client.webSocket(8080, "localhost", "/", onSuccess(ws -> {
ws.handler(buf -> {
ws.closeHandler(v -> {
vertx.close(v4 -> {
assertTrue(webSocketConnected.get());
assertTrue(webSocketDisconnected.get());
assertTrue(bytesReadCalled.get());
assertTrue(bytesWrittenCalled.get());
assertTrue(socketConnectedCalled.get());
assertTrue(socketDisconnectedCalled.get());
assertTrue(closeCalled.get());
testComplete();
});
});
ws.close();
});
ws.write(Buffer.buffer("hello"));
}));
await();
}
use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse-vertx.
the class MetricsContextTest method testHttpClientWebSocket.
private void testHttpClientWebSocket(Function<Vertx, Context> contextFactory) throws Exception {
AtomicBoolean webSocketConnected = new AtomicBoolean();
AtomicBoolean webSocketDisconnected = new AtomicBoolean();
AtomicBoolean socketConnectedCalled = new AtomicBoolean();
AtomicBoolean socketDisconnectedCalled = new AtomicBoolean();
AtomicBoolean bytesReadCalled = new AtomicBoolean();
AtomicBoolean bytesWrittenCalled = new AtomicBoolean();
AtomicBoolean closeCalled = new AtomicBoolean();
VertxMetricsFactory factory = (options) -> new DummyVertxMetrics() {
@Override
public HttpClientMetrics createHttpClientMetrics(HttpClientOptions options) {
return new DummyHttpClientMetrics() {
@Override
public ClientMetrics<Void, Void, HttpRequest, HttpResponse> createEndpointMetrics(SocketAddress remoteAddress, int maxPoolSize) {
return new ClientMetrics<Void, Void, HttpRequest, HttpResponse>() {
};
}
@Override
public Void connected(WebSocket webSocket) {
webSocketConnected.set(true);
return null;
}
@Override
public void disconnected(Void webSocketMetric) {
webSocketDisconnected.set(true);
}
@Override
public Void connected(SocketAddress remoteAddress, String remoteName) {
socketConnectedCalled.set(true);
return null;
}
@Override
public void disconnected(Void socketMetric, SocketAddress remoteAddress) {
socketDisconnectedCalled.set(true);
}
@Override
public void bytesRead(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
bytesReadCalled.set(true);
}
@Override
public void bytesWritten(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
bytesWrittenCalled.set(true);
}
@Override
public void close() {
closeCalled.set(true);
}
};
}
};
Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
HttpServer server = vertx.createHttpServer();
server.webSocketHandler(ws -> {
ws.handler(buf -> {
ws.write(Buffer.buffer("bye"));
});
});
CountDownLatch latch = new CountDownLatch(1);
server.listen(8080, "localhost", onSuccess(s -> {
latch.countDown();
}));
awaitLatch(latch);
Context ctx = contextFactory.apply(vertx);
ctx.runOnContext(v1 -> {
HttpClient client = vertx.createHttpClient();
client.webSocket(8080, "localhost", "/", onSuccess(ws -> {
ws.handler(buf -> {
ws.closeHandler(v2 -> {
executeInVanillaThread(() -> {
client.close();
vertx.close(v3 -> {
assertTrue(webSocketConnected.get());
assertTrue(webSocketDisconnected.get());
assertTrue(socketConnectedCalled.get());
assertTrue(socketDisconnectedCalled.get());
assertTrue(bytesReadCalled.get());
assertTrue(bytesWrittenCalled.get());
assertTrue(closeCalled.get());
testComplete();
});
});
});
ws.close();
});
ws.write(Buffer.buffer("hello"));
}));
});
await();
}
Aggregations