use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.
the class MetricsOptionsTest method testMetricsEnabledWithoutConfig.
@Test
public void testMetricsEnabledWithoutConfig() {
vertx.close();
vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true)));
VertxMetrics metrics = ((VertxInternal) vertx).metricsSPI();
assertNotNull(metrics);
assertTrue(metrics instanceof DummyVertxMetrics);
}
use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.
the class Starter method startVertx.
private Vertx startVertx(boolean clustered, boolean ha, Args args) {
MetricsOptions metricsOptions;
ServiceLoader<VertxMetricsFactory> factories = ServiceLoader.load(VertxMetricsFactory.class);
if (factories.iterator().hasNext()) {
VertxMetricsFactory factory = factories.iterator().next();
metricsOptions = factory.newOptions();
} else {
metricsOptions = new MetricsOptions();
}
configureFromSystemProperties(metricsOptions, METRICS_OPTIONS_PROP_PREFIX);
options = new VertxOptions().setMetricsOptions(metricsOptions);
configureFromSystemProperties(options, VERTX_OPTIONS_PROP_PREFIX);
if (clustered) {
log.info("Starting clustering...");
int clusterPort = args.getInt("-cluster-port");
if (clusterPort == -1) {
// Default to zero - this means choose an ephemeral port
clusterPort = 0;
}
String clusterHost = args.map.get("-cluster-host");
if (clusterHost == null) {
clusterHost = getDefaultAddress();
if (clusterHost == null) {
log.error("Unable to find a default network interface for clustering. Please specify one using -cluster-host");
return null;
} else {
log.info("No cluster-host specified so using address " + clusterHost);
}
}
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<AsyncResult<Vertx>> result = new AtomicReference<>();
options.setClusterHost(clusterHost).setClusterPort(clusterPort).setClustered(true);
if (ha) {
String haGroup = args.map.get("-hagroup");
int quorumSize = args.getInt("-quorum");
options.setHAEnabled(true);
if (haGroup != null) {
options.setHAGroup(haGroup);
}
if (quorumSize != -1) {
options.setQuorumSize(quorumSize);
}
}
beforeStartingVertx(options);
Vertx.clusteredVertx(options, ar -> {
result.set(ar);
latch.countDown();
});
try {
if (!latch.await(2, TimeUnit.MINUTES)) {
log.error("Timed out in starting clustered Vert.x");
return null;
}
} catch (InterruptedException e) {
log.error("Thread interrupted in startup");
return null;
}
if (result.get().failed()) {
log.error("Failed to form cluster");
result.get().cause().printStackTrace();
return null;
}
vertx = result.get().result();
} else {
beforeStartingVertx(options);
vertx = Vertx.vertx(options);
}
addShutdownHook();
afterStartingVertx();
return vertx;
}
use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.
the class BareCommand method startVertx.
/**
* Starts the vert.x instance.
*
* @return the created instance of vert.x
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
protected Vertx startVertx() {
MetricsOptions metricsOptions = getMetricsOptions();
options = new VertxOptions().setMetricsOptions(metricsOptions);
configureFromSystemProperties(options, VERTX_OPTIONS_PROP_PREFIX);
beforeStartingVertx(options);
Vertx instance;
if (isClustered()) {
log.info("Starting clustering...");
if (clusterHost == null) {
clusterHost = getDefaultAddress();
if (clusterHost == null) {
log.error("Unable to find a default network interface for clustering. Please specify one using -cluster-host");
return null;
} else {
log.info("No cluster-host specified so using address " + clusterHost);
}
}
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<AsyncResult<Vertx>> result = new AtomicReference<>();
options.setClusterHost(clusterHost).setClusterPort(clusterPort).setClustered(true);
if (getHA()) {
options.setHAEnabled(true);
if (haGroup != null) {
options.setHAGroup(haGroup);
}
if (quorum != -1) {
options.setQuorumSize(quorum);
}
}
create(options, ar -> {
result.set(ar);
latch.countDown();
});
try {
if (!latch.await(2, TimeUnit.MINUTES)) {
log.error("Timed out in starting clustered Vert.x");
return null;
}
} catch (InterruptedException e) {
log.error("Thread interrupted in startup");
Thread.currentThread().interrupt();
return null;
}
if (result.get().failed()) {
log.error("Failed to form cluster");
result.get().cause().printStackTrace();
return null;
}
instance = result.get().result();
} else {
instance = create(options);
}
addShutdownHook();
afterStartingVertx(instance);
return instance;
}
use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.
the class BareCommand method getMetricsOptions.
/**
* @return the metric options.
*/
protected MetricsOptions getMetricsOptions() {
MetricsOptions metricsOptions;
VertxMetricsFactory factory = ServiceHelper.loadFactoryOrNull(VertxMetricsFactory.class);
if (factory != null) {
metricsOptions = factory.newOptions();
} else {
metricsOptions = new MetricsOptions();
}
configureFromSystemProperties(metricsOptions, METRICS_OPTIONS_PROP_PREFIX);
return metricsOptions;
}
use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.
the class VertxOptionsTest method testJsonOptions.
@Test
public void testJsonOptions() {
VertxOptions options = new VertxOptions(new JsonObject());
assertEquals(0, options.getClusterPort());
assertEquals(-1, options.getClusterPublicPort());
assertEquals(20000, options.getClusterPingInterval());
assertEquals(20000, options.getClusterPingReplyInterval());
assertEquals(2 * Runtime.getRuntime().availableProcessors(), options.getEventLoopPoolSize());
assertEquals(20, options.getInternalBlockingPoolSize());
assertEquals(20, options.getWorkerPoolSize());
assertEquals(1000, options.getBlockedThreadCheckInterval());
assertEquals("localhost", options.getClusterHost());
assertNull(options.getClusterPublicHost());
assertEquals(null, options.getClusterManager());
assertEquals(2000l * 1000000, options.getMaxEventLoopExecuteTime());
assertEquals(1l * 60 * 1000 * 1000000, options.getMaxWorkerExecuteTime());
assertFalse(options.isHAEnabled());
assertEquals(1, options.getQuorumSize());
assertEquals(VertxOptions.DEFAULT_HA_GROUP, options.getHAGroup());
assertNotNull(options.getMetricsOptions());
assertEquals(5000000000l, options.getWarningExceptionTime());
int clusterPort = TestUtils.randomPortInt();
int clusterPublicPort = TestUtils.randomPortInt();
int eventLoopPoolSize = TestUtils.randomPositiveInt();
int internalBlockingPoolSize = TestUtils.randomPositiveInt();
int workerPoolSize = TestUtils.randomPositiveInt();
int blockedThreadCheckInterval = TestUtils.randomPositiveInt();
String clusterHost = TestUtils.randomAlphaString(100);
String clusterPublicHost = TestUtils.randomAlphaString(100);
long clusterPingInterval = TestUtils.randomPositiveLong();
long clusterPingReplyInterval = TestUtils.randomPositiveLong();
int maxEventLoopExecuteTime = TestUtils.randomPositiveInt();
int maxWorkerExecuteTime = TestUtils.randomPositiveInt();
int proxyOperationTimeout = TestUtils.randomPositiveInt();
long warningExceptionTime = TestUtils.randomPositiveLong();
Random rand = new Random();
boolean haEnabled = rand.nextBoolean();
int quorumSize = TestUtils.randomShort() + 1;
String haGroup = TestUtils.randomAlphaString(100);
boolean metricsEnabled = rand.nextBoolean();
boolean jmxEnabled = rand.nextBoolean();
String jmxDomain = TestUtils.randomAlphaString(100);
options = new VertxOptions(new JsonObject().put("clusterPort", clusterPort).put("clusterPublicPort", clusterPublicPort).put("eventLoopPoolSize", eventLoopPoolSize).put("internalBlockingPoolSize", internalBlockingPoolSize).put("workerPoolSize", workerPoolSize).put("blockedThreadCheckInterval", blockedThreadCheckInterval).put("clusterHost", clusterHost).put("clusterPublicHost", clusterPublicHost).put("clusterPingInterval", clusterPingInterval).put("clusterPingReplyInterval", clusterPingReplyInterval).put("maxEventLoopExecuteTime", maxEventLoopExecuteTime).put("maxWorkerExecuteTime", maxWorkerExecuteTime).put("proxyOperationTimeout", proxyOperationTimeout).put("haEnabled", haEnabled).put("quorumSize", quorumSize).put("haGroup", haGroup).put("warningExceptionTime", warningExceptionTime).put("metricsOptions", new JsonObject().put("enabled", metricsEnabled).put("jmxEnabled", jmxEnabled).put("jmxDomain", jmxDomain)));
assertEquals(clusterPort, options.getClusterPort());
assertEquals(clusterPublicPort, options.getClusterPublicPort());
assertEquals(clusterPublicHost, options.getClusterPublicHost());
assertEquals(clusterPingInterval, options.getClusterPingInterval());
assertEquals(clusterPingReplyInterval, options.getClusterPingReplyInterval());
assertEquals(eventLoopPoolSize, options.getEventLoopPoolSize());
assertEquals(internalBlockingPoolSize, options.getInternalBlockingPoolSize());
assertEquals(workerPoolSize, options.getWorkerPoolSize());
assertEquals(blockedThreadCheckInterval, options.getBlockedThreadCheckInterval());
assertEquals(clusterHost, options.getClusterHost());
assertEquals(null, options.getClusterManager());
assertEquals(maxEventLoopExecuteTime, options.getMaxEventLoopExecuteTime());
assertEquals(maxWorkerExecuteTime, options.getMaxWorkerExecuteTime());
assertEquals(haEnabled, options.isHAEnabled());
assertEquals(quorumSize, options.getQuorumSize());
assertEquals(haGroup, options.getHAGroup());
MetricsOptions metricsOptions = options.getMetricsOptions();
assertEquals(metricsEnabled, metricsOptions.isEnabled());
assertEquals(warningExceptionTime, options.getWarningExceptionTime());
}
Aggregations