Java Code Examples for org.apache.hadoop.metrics2.MetricsSystem#shutdown()

The following examples show how to use org.apache.hadoop.metrics2.MetricsSystem#shutdown() . 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: TestMetricsSystemImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test public void testUnregisterSource() {
  MetricsSystem ms = new MetricsSystemImpl();
  TestSource ts1 = new TestSource("ts1");
  TestSource ts2 = new TestSource("ts2");
  ms.register("ts1", "", ts1);
  ms.register("ts2", "", ts2);
  MetricsSource s1 = ms.getSource("ts1");
  assertNotNull(s1);
  // should work when metrics system is not started
  ms.unregisterSource("ts1");
  s1 = ms.getSource("ts1");
  assertNull(s1);
  MetricsSource s2 = ms.getSource("ts2");
  assertNotNull(s2);
  ms.shutdown();
}
 
Example 2
Source File: TestMetricsSystemImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test public void testRegisterSourceWithoutName() {
  MetricsSystem ms = new MetricsSystemImpl();
  TestSource ts = new TestSource("ts");
  TestSource2 ts2 = new TestSource2("ts2");
  ms.register(ts);
  ms.register(ts2);
  ms.init("TestMetricsSystem");
  // if metrics source is registered without name,
  // the class name will be used as the name
  MetricsSourceAdapter sa = ((MetricsSystemImpl) ms)
      .getSourceAdapter("TestSource");
  assertNotNull(sa);
  MetricsSourceAdapter sa2 = ((MetricsSystemImpl) ms)
      .getSourceAdapter("TestSource2");
  assertNotNull(sa2);
  ms.shutdown();
}
 
Example 3
Source File: TestMetricsSystemImpl.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test public void testUnregisterSource() {
  MetricsSystem ms = new MetricsSystemImpl();
  TestSource ts1 = new TestSource("ts1");
  TestSource ts2 = new TestSource("ts2");
  ms.register("ts1", "", ts1);
  ms.register("ts2", "", ts2);
  MetricsSource s1 = ms.getSource("ts1");
  assertNotNull(s1);
  // should work when metrics system is not started
  ms.unregisterSource("ts1");
  s1 = ms.getSource("ts1");
  assertNull(s1);
  MetricsSource s2 = ms.getSource("ts2");
  assertNotNull(s2);
  ms.shutdown();
}
 
Example 4
Source File: TestMetricsSystemImpl.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test public void testRegisterSourceWithoutName() {
  MetricsSystem ms = new MetricsSystemImpl();
  TestSource ts = new TestSource("ts");
  TestSource2 ts2 = new TestSource2("ts2");
  ms.register(ts);
  ms.register(ts2);
  ms.init("TestMetricsSystem");
  // if metrics source is registered without name,
  // the class name will be used as the name
  MetricsSourceAdapter sa = ((MetricsSystemImpl) ms)
      .getSourceAdapter("TestSource");
  assertNotNull(sa);
  MetricsSourceAdapter sa2 = ((MetricsSystemImpl) ms)
      .getSourceAdapter("TestSource2");
  assertNotNull(sa2);
  ms.shutdown();
}
 
Example 5
Source File: TestPrometheusMetricsSink.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Test
public void testPublish() throws IOException {
  //GIVEN
  MetricsSystem metrics = DefaultMetricsSystem.instance();

  metrics.init("test");
  PrometheusMetricsSink sink = new PrometheusMetricsSink();
  metrics.register("Prometheus", "Prometheus", sink);
  TestMetrics testMetrics = metrics
      .register("TestMetrics", "Testing metrics", new TestMetrics());

  metrics.start();
  testMetrics.numBucketCreateFails.incr();
  metrics.publishMetricsNow();
  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  OutputStreamWriter writer = new OutputStreamWriter(stream, UTF_8);

  //WHEN
  sink.writeMetrics(writer);
  writer.flush();

  //THEN
  String writtenMetrics = stream.toString(UTF_8.name());
  Assert.assertTrue(
      "The expected metric line is missing from prometheus metrics output",
      writtenMetrics.contains(
          "test_metrics_num_bucket_create_fails{context=\"dfs\"")
  );

  metrics.stop();
  metrics.shutdown();
}
 
Example 6
Source File: TestQueueMetrics.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test 
public void testMetricsCache() {
  MetricsSystem ms = new MetricsSystemImpl("cache");
  ms.start();
  
  try {
    String p1 = "root1";
    String leafQueueName = "root1.leaf";

    QueueMetrics p1Metrics =
        QueueMetrics.forQueue(ms, p1, null, true, conf);
    Queue parentQueue1 = make(stub(Queue.class).returning(p1Metrics).
        from.getMetrics());
    QueueMetrics metrics =
        QueueMetrics.forQueue(ms, leafQueueName, parentQueue1, true, conf);

    Assert.assertNotNull("QueueMetrics for A shoudn't be null", metrics);

    // Re-register to check for cache hit, shouldn't blow up metrics-system...
    // also, verify parent-metrics
    QueueMetrics alterMetrics =
        QueueMetrics.forQueue(ms, leafQueueName, parentQueue1, true, conf);

    Assert.assertNotNull("QueueMetrics for alterMetrics shoudn't be null", 
        alterMetrics);
  } finally {
    ms.shutdown();
  }
}
 
Example 7
Source File: TestMetricsSystemImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test public void testRegisterDups() {
  MetricsSystem ms = new MetricsSystemImpl();
  TestSource ts1 = new TestSource("ts1");
  TestSource ts2 = new TestSource("ts2");
  ms.register("ts1", "", ts1);
  MetricsSource s1 = ms.getSource("ts1");
  assertNotNull(s1);
  // should work when metrics system is not started
  ms.register("ts1", "", ts2);
  MetricsSource s2 = ms.getSource("ts1");
  assertNotNull(s2);
  assertNotSame(s1, s2);
  ms.shutdown();
}
 
Example 8
Source File: TestQueueMetrics.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test 
public void testMetricsCache() {
  MetricsSystem ms = new MetricsSystemImpl("cache");
  ms.start();
  
  try {
    String p1 = "root1";
    String leafQueueName = "root1.leaf";

    QueueMetrics p1Metrics =
        QueueMetrics.forQueue(ms, p1, null, true, conf);
    Queue parentQueue1 = make(stub(Queue.class).returning(p1Metrics).
        from.getMetrics());
    QueueMetrics metrics =
        QueueMetrics.forQueue(ms, leafQueueName, parentQueue1, true, conf);

    Assert.assertNotNull("QueueMetrics for A shoudn't be null", metrics);

    // Re-register to check for cache hit, shouldn't blow up metrics-system...
    // also, verify parent-metrics
    QueueMetrics alterMetrics =
        QueueMetrics.forQueue(ms, leafQueueName, parentQueue1, true, conf);

    Assert.assertNotNull("QueueMetrics for alterMetrics shoudn't be null", 
        alterMetrics);
  } finally {
    ms.shutdown();
  }
}
 
Example 9
Source File: TestMetricsSystemImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test public void testRegisterDups() {
  MetricsSystem ms = new MetricsSystemImpl();
  TestSource ts1 = new TestSource("ts1");
  TestSource ts2 = new TestSource("ts2");
  ms.register("ts1", "", ts1);
  MetricsSource s1 = ms.getSource("ts1");
  assertNotNull(s1);
  // should work when metrics system is not started
  ms.register("ts1", "", ts2);
  MetricsSource s2 = ms.getSource("ts1");
  assertNotNull(s2);
  assertNotSame(s1, s2);
  ms.shutdown();
}
 
Example 10
Source File: TestPrometheusMetricsSink.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@Test
public void testPublishWithSameName() throws IOException {
  //GIVEN
  MetricsSystem metrics = DefaultMetricsSystem.instance();

  metrics.init("test");
  PrometheusMetricsSink sink = new PrometheusMetricsSink();
  metrics.register("Prometheus", "Prometheus", sink);
  metrics.register("FooBar", "fooBar", (MetricsSource) (collector, all) -> {
    collector.addRecord("RpcMetrics").add(new MetricsTag(PORT_INFO, "1234"))
        .addGauge(COUNTER_INFO, 123).endRecord();

    collector.addRecord("RpcMetrics").add(new MetricsTag(
        PORT_INFO, "2345")).addGauge(COUNTER_INFO, 234).endRecord();
  });

  metrics.start();
  metrics.publishMetricsNow();

  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  OutputStreamWriter writer = new OutputStreamWriter(stream, UTF_8);

  //WHEN
  sink.writeMetrics(writer);
  writer.flush();

  //THEN
  String writtenMetrics = stream.toString(UTF_8.name());
  Assert.assertTrue(
      "The expected metric line is missing from prometheus metrics output",
      writtenMetrics.contains(
          "rpc_metrics_counter{port=\"2345\""));

  Assert.assertTrue(
      "The expected metric line is missing from prometheus metrics "
          + "output",
      writtenMetrics.contains(
          "rpc_metrics_counter{port=\"1234\""));

  metrics.stop();
  metrics.shutdown();
}