com.datastax.driver.core.Cluster.getMetrics()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中com.datastax.driver.core.Cluster.getMetrics()方法的一些代码示例,展示了Cluster.getMetrics()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cluster.getMetrics()方法的具体详情如下:
包路径:com.datastax.driver.core.Cluster
类名称:Cluster
方法名:getMetrics

Cluster.getMetrics介绍

[英]The cluster metrics.
[中]集群度量。

代码示例

代码示例来源:origin: kairosdb/kairosdb

  1. Metrics metrics = m_cluster.getMetrics();

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Override
  2. public Metrics getMetrics() {
  3. return delegate().getMetrics();
  4. }

代码示例来源:origin: pulsarIO/realtime-analytics

  1. private void connectInternal() {
  2. try {
  3. Cluster cluster = config.createBuilder().build();
  4. cassandraSession = cluster.connect(keySpace);
  5. cassandraMetrics = cluster.getMetrics();
  6. connected.set(true);
  7. } catch (Exception e) {
  8. LOGGER.error("Error connection to Cassandra" + e.getMessage());
  9. if (pool != null) {
  10. pool.shutdownNow();
  11. pool = null;
  12. }
  13. if (cassandraSession != null) {
  14. cassandraSession.close();
  15. if (cassandraSession.getCluster() != null)
  16. cassandraSession.getCluster().close();
  17. }
  18. connected.set(false);
  19. }
  20. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Override
  2. public void init(Cluster cluster, Collection<Host> hosts) {
  3. childPolicy.init(cluster, hosts);
  4. for (Host host : hosts) {
  5. latencyTracker.addHost(host);
  6. }
  7. cluster.register(latencyTracker);
  8. metrics = cluster.getMetrics();
  9. if (metrics != null) {
  10. metrics
  11. .getRegistry()
  12. .register(
  13. "LatencyAwarePolicy.latencies.min",
  14. new Gauge<Long>() {
  15. @Override
  16. public Long getValue() {
  17. return latencyTracker.getMinAverage();
  18. }
  19. });
  20. }
  21. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. assertThat(cluster().getMetrics().getOpenConnections().getValue())
  2. .isEqualTo(TestUtils.numberOfLocalCoreConnections(cluster()) + 1);
  3. assertThat(cluster().getMetrics().getOpenConnections().getValue()).isEqualTo(1);

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Test(groups = "short")
  2. public void retriesTest() {
  3. retryDecision = RetryDecision.retry(ConsistencyLevel.ONE);
  4. // We only have one node, this will throw an unavailable exception
  5. Statement statement =
  6. new SimpleStatement("SELECT v FROM test WHERE k = 1")
  7. .setConsistencyLevel(ConsistencyLevel.TWO);
  8. session().execute(statement);
  9. Errors errors = cluster().getMetrics().getErrorMetrics();
  10. assertEquals(errors.getUnavailables().getCount(), 1);
  11. assertEquals(errors.getRetries().getCount(), 1);
  12. assertEquals(errors.getRetriesOnUnavailable().getCount(), 1);
  13. retryDecision = RetryDecision.ignore();
  14. session().execute(statement);
  15. assertEquals(errors.getUnavailables().getCount(), 2);
  16. assertEquals(errors.getIgnores().getCount(), 1);
  17. assertEquals(errors.getIgnoresOnUnavailable().getCount(), 1);
  18. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. private void assertOpenConnections(int expected, Cluster cluster) {
  2. assertThat(cluster.getMetrics().getOpenConnections().getValue()).isEqualTo(expected);
  3. assertThat(channelMonitor.openChannels(ccm().addressOfNode(1), ccm().addressOfNode(2)).size())
  4. .isEqualTo(expected);
  5. }
  6. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1);
  2. assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), 1);
  3. assertEquals(cluster.manager.sessions.size(), 1);
  4. assertEquals(
  5. (int) cluster.getMetrics().getOpenConnections().getValue(),
  6. 1 + TestUtils.numberOfLocalCoreConnections(cluster));
  7. assertEquals(
  8. assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1);
  9. assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), 1);

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Test(groups = "short")
  2. public void should_preserve_timestamp_when_retrying() {
  3. SimpleStatement statement = new SimpleStatement("INSERT INTO foo (k, v) VALUES (1, 1)");
  4. statement.setDefaultTimestamp(10);
  5. // This will fail since we test against a single-host cluster. The
  6. // DowngradingConsistencyRetryPolicy
  7. // will retry it at ONE.
  8. statement.setConsistencyLevel(ConsistencyLevel.TWO);
  9. session().execute(statement);
  10. Errors metrics = session().getCluster().getMetrics().getErrorMetrics();
  11. assertEquals(metrics.getRetriesOnUnavailable().getCount(), 1);
  12. long writeTime = session().execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0);
  13. assertEquals(writeTime, 10);
  14. }
  15. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Test(groups = "short")
  2. public void testMissingRpcAddressAtStartup() throws Exception {
  3. deleteNode2RpcAddressFromNode1();
  4. // Use only one contact point to make sure that the control connection is on node1
  5. Cluster cluster =
  6. register(
  7. Cluster.builder()
  8. .addContactPoints(getContactPoints().get(0))
  9. .withPort(ccm().getBinaryPort())
  10. .build());
  11. cluster.connect();
  12. // Since node2's RPC address is unknown on our control host, it should have been ignored
  13. assertEquals(cluster.getMetrics().getConnectedToHosts().getValue().intValue(), 1);
  14. assertNull(cluster.getMetadata().getHost(getContactPointsWithPorts().get(1)));
  15. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. /**
  2. * Validates that metrics are enabled and exposed by JMX by default by checking that {@link
  3. * Cluster#getMetrics()} is not null and 'clusterName-metrics:name=connected-to' MBean is present.
  4. *
  5. * @test_category metrics
  6. */
  7. @Test(groups = "short")
  8. public void should_enable_metrics_and_jmx_by_default() throws Exception {
  9. assertThat(cluster().getMetrics()).isNotNull();
  10. ObjectName clusterMetricsON =
  11. ObjectName.getInstance(cluster().getClusterName() + "-metrics:name=connected-to");
  12. MBeanInfo mBean = server.getMBeanInfo(clusterMetricsON);
  13. assertThat(mBean).isNotNull();
  14. assertThat(cluster().getConfiguration().getMetricsOptions().isEnabled()).isTrue();
  15. assertThat(cluster().getConfiguration().getMetricsOptions().isJMXReportingEnabled()).isTrue();
  16. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Test(groups = "short")
  2. public void should_connect_with_credentials() {
  3. PlainTextAuthProvider authProvider = spy(new PlainTextAuthProvider("cassandra", "cassandra"));
  4. Cluster cluster =
  5. Cluster.builder()
  6. .addContactPoints(getContactPoints())
  7. .withPort(ccm().getBinaryPort())
  8. .withAuthProvider(authProvider)
  9. .build();
  10. cluster.connect();
  11. verify(authProvider, atLeastOnce())
  12. .newAuthenticator(
  13. findHost(cluster, 1).getSocketAddress(),
  14. "org.apache.cassandra.auth.PasswordAuthenticator");
  15. assertThat(cluster.getMetrics().getErrorMetrics().getAuthenticationErrors().getCount())
  16. .isEqualTo(0);
  17. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Test(groups = "short")
  2. public void should_countdown_inflight_requests_metrics() {
  3. sCluster
  4. .node(1)
  5. .primingClient()
  6. .prime(PrimingRequest.queryBuilder().withQuery("mock query").withThen(then()).build());
  7. Cluster cluster = null;
  8. try {
  9. cluster = builder().build();
  10. Session session = cluster.connect();
  11. assertThat(cluster.getMetrics().getInFlightRequests().getValue()).isEqualTo(0);
  12. session.executeAsync("mock query").getUninterruptibly();
  13. session.executeAsync("mock query").getUninterruptibly();
  14. assertThat(cluster.getMetrics().getInFlightRequests().getValue()).isEqualTo(0);
  15. } finally {
  16. if (cluster != null) {
  17. cluster.close();
  18. }
  19. }
  20. }
  21. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Test(groups = "short")
  2. public void should_count_inflight_requests_metrics() {
  3. sCluster
  4. .node(1)
  5. .primingClient()
  6. .prime(
  7. PrimingRequest.queryBuilder()
  8. .withQuery("mock query")
  9. .withThen(then().withFixedDelay(100000L))
  10. .build());
  11. Cluster cluster = null;
  12. try {
  13. cluster = builder().build();
  14. Session session = cluster.connect();
  15. assertThat(cluster.getMetrics().getInFlightRequests().getValue()).isEqualTo(0);
  16. session.executeAsync("mock query");
  17. session.executeAsync("mock query");
  18. assertThat(cluster.getMetrics().getInFlightRequests().getValue()).isEqualTo(2);
  19. } finally {
  20. if (cluster != null) {
  21. cluster.close();
  22. }
  23. }
  24. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. /**
  2. * Validates that when metrics are enabled but JMX reporting is disabled via {@link
  3. * Cluster.Builder#withoutJMXReporting()} that {@link Cluster#getMetrics()} is not null and
  4. * 'clusterName-metrics:name=connected-to' MBean is present.
  5. *
  6. * @test_category metrics
  7. */
  8. @Test(groups = "short", expectedExceptions = InstanceNotFoundException.class)
  9. public void should_be_no_jmx_mbean_when_jmx_is_disabled() throws Exception {
  10. Cluster cluster =
  11. register(
  12. Cluster.builder()
  13. .addContactPoints(getContactPoints())
  14. .withPort(ccm().getBinaryPort())
  15. .withoutJMXReporting()
  16. .build());
  17. try {
  18. cluster.init();
  19. assertThat(cluster.getMetrics()).isNotNull();
  20. assertThat(cluster.getConfiguration().getMetricsOptions().isEnabled()).isTrue();
  21. assertThat(cluster.getConfiguration().getMetricsOptions().isJMXReportingEnabled()).isFalse();
  22. ObjectName clusterMetricsON =
  23. ObjectName.getInstance(cluster.getClusterName() + "-metrics:name=connected-to");
  24. server.getMBeanInfo(clusterMetricsON);
  25. } finally {
  26. cluster.close();
  27. }
  28. }
  29. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @BeforeMethod(groups = "short")
  2. public void beforeMethod() {
  3. cluster =
  4. Cluster.builder()
  5. .addContactPoints(scassandras.address(1).getAddress())
  6. .withPort(scassandras.getBinaryPort())
  7. .withRetryPolicy(FallthroughRetryPolicy.INSTANCE)
  8. .build();
  9. session = cluster.connect();
  10. host1 = TestUtils.findHost(cluster, 1);
  11. errors = cluster.getMetrics().getErrorMetrics();
  12. for (Scassandra node : scassandras.nodes()) {
  13. node.primingClient().clearAllPrimes();
  14. node.activityClient().clearAllRecordedActivity();
  15. }
  16. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. /**
  2. * Validates that when metrics are disabled using {@link Cluster.Builder#withoutMetrics()} that
  3. * {@link Cluster#getMetrics()} returns null and 'clusterName-metrics:name=connected-to' MBean is
  4. * not present.
  5. *
  6. * @test_category metrics
  7. */
  8. @Test(groups = "short", expectedExceptions = InstanceNotFoundException.class)
  9. public void metrics_should_be_null_when_metrics_disabled() throws Exception {
  10. Cluster cluster =
  11. register(
  12. Cluster.builder()
  13. .addContactPoints(getContactPoints())
  14. .withPort(ccm().getBinaryPort())
  15. .withoutMetrics()
  16. .build());
  17. try {
  18. cluster.init();
  19. assertThat(cluster.getMetrics()).isNull();
  20. assertThat(cluster.getConfiguration().getMetricsOptions().isEnabled()).isFalse();
  21. ObjectName clusterMetricsON =
  22. ObjectName.getInstance(cluster.getClusterName() + "-metrics:name=connected-to");
  23. server.getMBeanInfo(clusterMetricsON);
  24. } finally {
  25. cluster.close();
  26. }
  27. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @BeforeMethod(groups = "short")
  2. public void beforeMethod() {
  3. scassandras = ScassandraCluster.builder().withNodes(3).build();
  4. scassandras.init();
  5. int speculativeExecutionDelay = 200;
  6. loadBalancingPolicy = new SortingLoadBalancingPolicy();
  7. cluster =
  8. Cluster.builder()
  9. .addContactPoints(scassandras.address(2).getAddress())
  10. .withPort(scassandras.getBinaryPort())
  11. .withLoadBalancingPolicy(loadBalancingPolicy)
  12. .withSpeculativeExecutionPolicy(
  13. new ConstantSpeculativeExecutionPolicy(speculativeExecutionDelay, 1))
  14. .withQueryOptions(new QueryOptions().setDefaultIdempotence(true))
  15. .withRetryPolicy(new CustomRetryPolicy())
  16. .withNettyOptions(nonQuietClusterCloseOptions)
  17. .build();
  18. session = cluster.connect();
  19. host1 = TestUtils.findHost(cluster, 1);
  20. host2 = TestUtils.findHost(cluster, 2);
  21. host3 = TestUtils.findHost(cluster, 3);
  22. errors = cluster.getMetrics().getErrorMetrics();
  23. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @BeforeMethod(groups = "short")
  2. public void beforeMethod() {
  3. scassandras = ScassandraCluster.builder().withNodes(3).build();
  4. scassandras.init();
  5. cluster =
  6. Cluster.builder()
  7. .addContactPoints(scassandras.address(1).getAddress())
  8. .withPort(scassandras.getBinaryPort())
  9. .withRetryPolicy(retryPolicy)
  10. .withLoadBalancingPolicy(new SortingLoadBalancingPolicy())
  11. .withPoolingOptions(
  12. new PoolingOptions()
  13. .setCoreConnectionsPerHost(HostDistance.LOCAL, 1)
  14. .setMaxConnectionsPerHost(HostDistance.LOCAL, 1)
  15. .setHeartbeatIntervalSeconds(0))
  16. .withNettyOptions(nonQuietClusterCloseOptions)
  17. // Mark everything as idempotent by default so RetryPolicy is exercised.
  18. .withQueryOptions(new QueryOptions().setDefaultIdempotence(true))
  19. .build();
  20. session = cluster.connect();
  21. host1 = TestUtils.findHost(cluster, 1);
  22. host2 = TestUtils.findHost(cluster, 2);
  23. host3 = TestUtils.findHost(cluster, 3);
  24. errors = cluster.getMetrics().getErrorMetrics();
  25. Mockito.reset(retryPolicy);
  26. for (Scassandra node : scassandras.nodes()) {
  27. node.activityClient().clearAllRecordedActivity();
  28. }
  29. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Test(groups = "short")
  2. public void should_measure_inbound_and_outbound_traffic() {
  3. Metrics metrics = session().getCluster().getMetrics();
  4. Meter bytesReceived = metrics.getBytesReceived();
  5. Meter bytesSent = metrics.getBytesSent();

相关文章