本文整理了Java中com.datastax.driver.core.Cluster.getMetrics()
方法的一些代码示例,展示了Cluster.getMetrics()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cluster.getMetrics()
方法的具体详情如下:
包路径:com.datastax.driver.core.Cluster
类名称:Cluster
方法名:getMetrics
[英]The cluster metrics.
[中]集群度量。
代码示例来源:origin: kairosdb/kairosdb
Metrics metrics = m_cluster.getMetrics();
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public Metrics getMetrics() {
return delegate().getMetrics();
}
代码示例来源:origin: pulsarIO/realtime-analytics
private void connectInternal() {
try {
Cluster cluster = config.createBuilder().build();
cassandraSession = cluster.connect(keySpace);
cassandraMetrics = cluster.getMetrics();
connected.set(true);
} catch (Exception e) {
LOGGER.error("Error connection to Cassandra" + e.getMessage());
if (pool != null) {
pool.shutdownNow();
pool = null;
}
if (cassandraSession != null) {
cassandraSession.close();
if (cassandraSession.getCluster() != null)
cassandraSession.getCluster().close();
}
connected.set(false);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public void init(Cluster cluster, Collection<Host> hosts) {
childPolicy.init(cluster, hosts);
for (Host host : hosts) {
latencyTracker.addHost(host);
}
cluster.register(latencyTracker);
metrics = cluster.getMetrics();
if (metrics != null) {
metrics
.getRegistry()
.register(
"LatencyAwarePolicy.latencies.min",
new Gauge<Long>() {
@Override
public Long getValue() {
return latencyTracker.getMinAverage();
}
});
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
assertThat(cluster().getMetrics().getOpenConnections().getValue())
.isEqualTo(TestUtils.numberOfLocalCoreConnections(cluster()) + 1);
assertThat(cluster().getMetrics().getOpenConnections().getValue()).isEqualTo(1);
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void retriesTest() {
retryDecision = RetryDecision.retry(ConsistencyLevel.ONE);
// We only have one node, this will throw an unavailable exception
Statement statement =
new SimpleStatement("SELECT v FROM test WHERE k = 1")
.setConsistencyLevel(ConsistencyLevel.TWO);
session().execute(statement);
Errors errors = cluster().getMetrics().getErrorMetrics();
assertEquals(errors.getUnavailables().getCount(), 1);
assertEquals(errors.getRetries().getCount(), 1);
assertEquals(errors.getRetriesOnUnavailable().getCount(), 1);
retryDecision = RetryDecision.ignore();
session().execute(statement);
assertEquals(errors.getUnavailables().getCount(), 2);
assertEquals(errors.getIgnores().getCount(), 1);
assertEquals(errors.getIgnoresOnUnavailable().getCount(), 1);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
private void assertOpenConnections(int expected, Cluster cluster) {
assertThat(cluster.getMetrics().getOpenConnections().getValue()).isEqualTo(expected);
assertThat(channelMonitor.openChannels(ccm().addressOfNode(1), ccm().addressOfNode(2)).size())
.isEqualTo(expected);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1);
assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), 1);
assertEquals(cluster.manager.sessions.size(), 1);
assertEquals(
(int) cluster.getMetrics().getOpenConnections().getValue(),
1 + TestUtils.numberOfLocalCoreConnections(cluster));
assertEquals(
assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1);
assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), 1);
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_preserve_timestamp_when_retrying() {
SimpleStatement statement = new SimpleStatement("INSERT INTO foo (k, v) VALUES (1, 1)");
statement.setDefaultTimestamp(10);
// This will fail since we test against a single-host cluster. The
// DowngradingConsistencyRetryPolicy
// will retry it at ONE.
statement.setConsistencyLevel(ConsistencyLevel.TWO);
session().execute(statement);
Errors metrics = session().getCluster().getMetrics().getErrorMetrics();
assertEquals(metrics.getRetriesOnUnavailable().getCount(), 1);
long writeTime = session().execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0);
assertEquals(writeTime, 10);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void testMissingRpcAddressAtStartup() throws Exception {
deleteNode2RpcAddressFromNode1();
// Use only one contact point to make sure that the control connection is on node1
Cluster cluster =
register(
Cluster.builder()
.addContactPoints(getContactPoints().get(0))
.withPort(ccm().getBinaryPort())
.build());
cluster.connect();
// Since node2's RPC address is unknown on our control host, it should have been ignored
assertEquals(cluster.getMetrics().getConnectedToHosts().getValue().intValue(), 1);
assertNull(cluster.getMetadata().getHost(getContactPointsWithPorts().get(1)));
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Validates that metrics are enabled and exposed by JMX by default by checking that {@link
* Cluster#getMetrics()} is not null and 'clusterName-metrics:name=connected-to' MBean is present.
*
* @test_category metrics
*/
@Test(groups = "short")
public void should_enable_metrics_and_jmx_by_default() throws Exception {
assertThat(cluster().getMetrics()).isNotNull();
ObjectName clusterMetricsON =
ObjectName.getInstance(cluster().getClusterName() + "-metrics:name=connected-to");
MBeanInfo mBean = server.getMBeanInfo(clusterMetricsON);
assertThat(mBean).isNotNull();
assertThat(cluster().getConfiguration().getMetricsOptions().isEnabled()).isTrue();
assertThat(cluster().getConfiguration().getMetricsOptions().isJMXReportingEnabled()).isTrue();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_connect_with_credentials() {
PlainTextAuthProvider authProvider = spy(new PlainTextAuthProvider("cassandra", "cassandra"));
Cluster cluster =
Cluster.builder()
.addContactPoints(getContactPoints())
.withPort(ccm().getBinaryPort())
.withAuthProvider(authProvider)
.build();
cluster.connect();
verify(authProvider, atLeastOnce())
.newAuthenticator(
findHost(cluster, 1).getSocketAddress(),
"org.apache.cassandra.auth.PasswordAuthenticator");
assertThat(cluster.getMetrics().getErrorMetrics().getAuthenticationErrors().getCount())
.isEqualTo(0);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_countdown_inflight_requests_metrics() {
sCluster
.node(1)
.primingClient()
.prime(PrimingRequest.queryBuilder().withQuery("mock query").withThen(then()).build());
Cluster cluster = null;
try {
cluster = builder().build();
Session session = cluster.connect();
assertThat(cluster.getMetrics().getInFlightRequests().getValue()).isEqualTo(0);
session.executeAsync("mock query").getUninterruptibly();
session.executeAsync("mock query").getUninterruptibly();
assertThat(cluster.getMetrics().getInFlightRequests().getValue()).isEqualTo(0);
} finally {
if (cluster != null) {
cluster.close();
}
}
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_count_inflight_requests_metrics() {
sCluster
.node(1)
.primingClient()
.prime(
PrimingRequest.queryBuilder()
.withQuery("mock query")
.withThen(then().withFixedDelay(100000L))
.build());
Cluster cluster = null;
try {
cluster = builder().build();
Session session = cluster.connect();
assertThat(cluster.getMetrics().getInFlightRequests().getValue()).isEqualTo(0);
session.executeAsync("mock query");
session.executeAsync("mock query");
assertThat(cluster.getMetrics().getInFlightRequests().getValue()).isEqualTo(2);
} finally {
if (cluster != null) {
cluster.close();
}
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Validates that when metrics are enabled but JMX reporting is disabled via {@link
* Cluster.Builder#withoutJMXReporting()} that {@link Cluster#getMetrics()} is not null and
* 'clusterName-metrics:name=connected-to' MBean is present.
*
* @test_category metrics
*/
@Test(groups = "short", expectedExceptions = InstanceNotFoundException.class)
public void should_be_no_jmx_mbean_when_jmx_is_disabled() throws Exception {
Cluster cluster =
register(
Cluster.builder()
.addContactPoints(getContactPoints())
.withPort(ccm().getBinaryPort())
.withoutJMXReporting()
.build());
try {
cluster.init();
assertThat(cluster.getMetrics()).isNotNull();
assertThat(cluster.getConfiguration().getMetricsOptions().isEnabled()).isTrue();
assertThat(cluster.getConfiguration().getMetricsOptions().isJMXReportingEnabled()).isFalse();
ObjectName clusterMetricsON =
ObjectName.getInstance(cluster.getClusterName() + "-metrics:name=connected-to");
server.getMBeanInfo(clusterMetricsON);
} finally {
cluster.close();
}
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@BeforeMethod(groups = "short")
public void beforeMethod() {
cluster =
Cluster.builder()
.addContactPoints(scassandras.address(1).getAddress())
.withPort(scassandras.getBinaryPort())
.withRetryPolicy(FallthroughRetryPolicy.INSTANCE)
.build();
session = cluster.connect();
host1 = TestUtils.findHost(cluster, 1);
errors = cluster.getMetrics().getErrorMetrics();
for (Scassandra node : scassandras.nodes()) {
node.primingClient().clearAllPrimes();
node.activityClient().clearAllRecordedActivity();
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Validates that when metrics are disabled using {@link Cluster.Builder#withoutMetrics()} that
* {@link Cluster#getMetrics()} returns null and 'clusterName-metrics:name=connected-to' MBean is
* not present.
*
* @test_category metrics
*/
@Test(groups = "short", expectedExceptions = InstanceNotFoundException.class)
public void metrics_should_be_null_when_metrics_disabled() throws Exception {
Cluster cluster =
register(
Cluster.builder()
.addContactPoints(getContactPoints())
.withPort(ccm().getBinaryPort())
.withoutMetrics()
.build());
try {
cluster.init();
assertThat(cluster.getMetrics()).isNull();
assertThat(cluster.getConfiguration().getMetricsOptions().isEnabled()).isFalse();
ObjectName clusterMetricsON =
ObjectName.getInstance(cluster.getClusterName() + "-metrics:name=connected-to");
server.getMBeanInfo(clusterMetricsON);
} finally {
cluster.close();
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@BeforeMethod(groups = "short")
public void beforeMethod() {
scassandras = ScassandraCluster.builder().withNodes(3).build();
scassandras.init();
int speculativeExecutionDelay = 200;
loadBalancingPolicy = new SortingLoadBalancingPolicy();
cluster =
Cluster.builder()
.addContactPoints(scassandras.address(2).getAddress())
.withPort(scassandras.getBinaryPort())
.withLoadBalancingPolicy(loadBalancingPolicy)
.withSpeculativeExecutionPolicy(
new ConstantSpeculativeExecutionPolicy(speculativeExecutionDelay, 1))
.withQueryOptions(new QueryOptions().setDefaultIdempotence(true))
.withRetryPolicy(new CustomRetryPolicy())
.withNettyOptions(nonQuietClusterCloseOptions)
.build();
session = cluster.connect();
host1 = TestUtils.findHost(cluster, 1);
host2 = TestUtils.findHost(cluster, 2);
host3 = TestUtils.findHost(cluster, 3);
errors = cluster.getMetrics().getErrorMetrics();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@BeforeMethod(groups = "short")
public void beforeMethod() {
scassandras = ScassandraCluster.builder().withNodes(3).build();
scassandras.init();
cluster =
Cluster.builder()
.addContactPoints(scassandras.address(1).getAddress())
.withPort(scassandras.getBinaryPort())
.withRetryPolicy(retryPolicy)
.withLoadBalancingPolicy(new SortingLoadBalancingPolicy())
.withPoolingOptions(
new PoolingOptions()
.setCoreConnectionsPerHost(HostDistance.LOCAL, 1)
.setMaxConnectionsPerHost(HostDistance.LOCAL, 1)
.setHeartbeatIntervalSeconds(0))
.withNettyOptions(nonQuietClusterCloseOptions)
// Mark everything as idempotent by default so RetryPolicy is exercised.
.withQueryOptions(new QueryOptions().setDefaultIdempotence(true))
.build();
session = cluster.connect();
host1 = TestUtils.findHost(cluster, 1);
host2 = TestUtils.findHost(cluster, 2);
host3 = TestUtils.findHost(cluster, 3);
errors = cluster.getMetrics().getErrorMetrics();
Mockito.reset(retryPolicy);
for (Scassandra node : scassandras.nodes()) {
node.activityClient().clearAllRecordedActivity();
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_measure_inbound_and_outbound_traffic() {
Metrics metrics = session().getCluster().getMetrics();
Meter bytesReceived = metrics.getBytesReceived();
Meter bytesSent = metrics.getBytesSent();
内容来源于网络,如有侵权,请联系作者删除!