Java Code Examples for com.codahale.metrics.ConsoleReporter#close()

The following examples show how to use com.codahale.metrics.ConsoleReporter#close() . 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: NodeTest.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
@Test
public void testNodeMetrics() throws Exception {
    final List<PeerId> peers = TestUtils.generatePeers(3);

    final TestCluster cluster = new TestCluster("unittest", this.dataPath, peers);
    for (final PeerId peer : peers) {
        assertTrue(cluster.start(peer.getEndpoint(), false, 300, true));
    }

    // elect leader
    cluster.waitLeader();

    // get leader
    final Node leader = cluster.getLeader();
    assertNotNull(leader);
    assertEquals(3, leader.listPeers().size());
    // apply tasks to leader
    this.sendTestTaskAndWait(leader);

    {
        final ByteBuffer data = ByteBuffer.wrap("no closure".getBytes());
        final Task task = new Task(data, null);
        leader.apply(task);
    }

    cluster.ensureSame(-1);
    for (final Node node : cluster.getNodes()) {
        System.out.println("-------------" + node.getNodeId() + "-------------");
        final ConsoleReporter reporter = ConsoleReporter.forRegistry(node.getNodeMetrics().getMetricRegistry())
            .build();
        reporter.report();
        reporter.close();
        System.out.println();
    }
    // TODO check http status
    assertEquals(2, cluster.getFollowers().size());
    cluster.stopAll();
    //   System.out.println(node.getNodeMetrics().getMetrics());
}
 
Example 2
Source File: MetricsReporting.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
public static Consumer<RatisMetricRegistry> stopConsoleReporter() {
  return ratisMetricRegistry -> {
    ConsoleReporter reporter = ratisMetricRegistry.getConsoleReporter();
    if (reporter != null) {
      reporter.close();
    }
  };
}
 
Example 3
Source File: MemoryUsageGaugeSetTest.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Test
public void testJVMMetrics() throws InterruptedException {
    LOG.info("Starting testJVMMetrics");
    final MetricRegistry metrics = new MetricRegistry();
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)
        .convertRatesTo(TimeUnit.SECONDS)
        .convertDurationsTo(TimeUnit.MILLISECONDS)
        .build();
    metrics.registerAll(new MemoryUsageGaugeSet());
    metrics.register("sample", (Gauge<Double>) () -> 0.1234);
    reporter.start(1, TimeUnit.SECONDS);
    reporter.close();
}