org.apache.hadoop.metrics2.MetricsSystem Java Examples

The following examples show how to use org.apache.hadoop.metrics2.MetricsSystem. 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: QueueMetrics.java    From big-c with Apache License 2.0 6 votes vote down vote up
public synchronized 
static QueueMetrics forQueue(MetricsSystem ms, String queueName,
                                    Queue parent, boolean enableUserMetrics,
		      Configuration conf) {
  QueueMetrics metrics = queueMetrics.get(queueName);
  if (metrics == null) {
    metrics =
        new QueueMetrics(ms, queueName, parent, enableUserMetrics, conf).
        tag(QUEUE_INFO, queueName);
    
    // Register with the MetricsSystems
    if (ms != null) {
      metrics = 
          ms.register(
              sourceName(queueName).toString(), 
              "Metrics for queue: " + queueName, metrics);
    }
    queueMetrics.put(queueName, metrics);
  }

  return metrics;
}
 
Example #2
Source File: HadoopMetrics2Reporter.java    From kylin with Apache License 2.0 6 votes vote down vote up
private HadoopMetrics2Reporter(MetricRegistry registry, TimeUnit rateUnit, TimeUnit durationUnit,
        MetricFilter filter, MetricsSystem metrics2System, String jmxContext, String description, String recordName,
        String context) {
    super(registry, "hadoop-metrics2-reporter", filter, rateUnit, durationUnit);
    this.metrics2Registry = new MetricsRegistry(Interns.info(jmxContext, description));
    this.metrics2System = metrics2System;
    this.recordName = recordName;
    this.context = context;

    // These could really be Collection.emptyMap(), but this makes testing a bit easier.
    this.dropwizardGauges = EMPTY_GAUGE_MAP;
    this.dropwizardCounters = EMPTY_COUNTER_MAP;
    this.dropwizardHistograms = EMPTY_HISTOGRAM_MAP;
    this.dropwizardMeters = EMPTY_METER_MAP;
    this.dropwizardTimers = EMPTY_TIMER_MAP;

    // Register this source with the Metrics2 system.
    // Make sure this is the last thing done as getMetrics() can be called at any time after.
    this.metrics2System.register(Objects.requireNonNull(jmxContext), Objects.requireNonNull(description), this);
}
 
Example #3
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 #4
Source File: TestShuffleHandler.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Validate shuffle connection and input/output metrics.
 *
 * @throws Exception exception
 */
@Test (timeout = 10000)
public void testShuffleMetrics() throws Exception {
  MetricsSystem ms = new MetricsSystemImpl();
  ShuffleHandler sh = new ShuffleHandler(ms);
  ChannelFuture cf = make(stub(ChannelFuture.class).
      returning(true, false).from.isSuccess());

  sh.metrics.shuffleConnections.incr();
  sh.metrics.shuffleOutputBytes.incr(1*MiB);
  sh.metrics.shuffleConnections.incr();
  sh.metrics.shuffleOutputBytes.incr(2*MiB);

  checkShuffleMetrics(ms, 3*MiB, 0 , 0, 2);

  sh.metrics.operationComplete(cf);
  sh.metrics.operationComplete(cf);

  checkShuffleMetrics(ms, 3*MiB, 1, 1, 0);
}
 
Example #5
Source File: Metrics.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public static MetricsSystem initialize() {
    // if the jars aren't on the classpath, then we don't start the metrics system
    if (manager == null) {
        LOGGER.warn("Phoenix metrics could not be initialized - no MetricsManager found!");
        return null;
    }
    // only initialize the metrics system once
    synchronized (Metrics.class) {
        if (!initialized) {
            LOGGER.info("Initializing metrics system: " + Metrics.METRICS_SYSTEM_NAME);
            manager.init(Metrics.METRICS_SYSTEM_NAME);
            initialized = true;
        }
    }
    return manager;
}
 
Example #6
Source File: EventWatcher.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
public void start(EventQueue queue) {

    queue.addHandler(startEvent, this::handleStartEvent);

    queue.addHandler(completionEvent, (completionPayload, publisher) -> {
      try {
        handleCompletion(completionPayload, publisher);
      } catch (LeaseNotFoundException e) {
        //It's already done. Too late, we already retried it.
        //Not a real problem.
        LOG.warn("Completion event without active lease. Id={}",
            completionPayload.getId());
      }
    });

    MetricsSystem ms = DefaultMetricsSystem.instance();
    ms.register(name, "EventWatcher metrics", metrics);
  }
 
Example #7
Source File: ContainerMetrics.java    From hadoop with Apache License 2.0 6 votes vote down vote up
synchronized static ContainerMetrics forContainer(
    MetricsSystem ms, ContainerId containerId, long flushPeriodMs) {
  ContainerMetrics metrics = usageMetrics.get(containerId);
  if (metrics == null) {
    metrics = new ContainerMetrics(
        ms, containerId, flushPeriodMs).tag(RECORD_INFO, containerId);

    // Register with the MetricsSystems
    if (ms != null) {
      metrics =
          ms.register(sourceName(containerId),
              "Metrics for container: " + containerId, metrics);
    }
    usageMetrics.put(containerId, metrics);
  }

  return metrics;
}
 
Example #8
Source File: TestRocksDBStoreMBean.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
@Test
public void testMetricsSystemIntegration() throws Exception {

  RocksDBStore metadataStore = getTestRocksDBStoreWithData();
  Thread.sleep(2000);

  MetricsSystem ms = DefaultMetricsSystem.instance();
  MetricsSource rdbSource =
      ms.getSource("Rocksdb_TestRocksDBStoreMBean-withstat");

  BufferedMetricsCollector metricsCollector = new BufferedMetricsCollector();
  rdbSource.getMetrics(metricsCollector, true);

  Map<String, Double> metrics = metricsCollector.getMetricsRecordBuilder()
      .getMetrics();
  assertTrue(10.0 == metrics.get("NUMBER_KEYS_WRITTEN"));
  assertTrue(metrics.get("DB_WRITE_AVERAGE") > 0);
  metadataStore.close();
}
 
Example #9
Source File: ContainerMetrics.java    From big-c with Apache License 2.0 6 votes vote down vote up
ContainerMetrics(
    MetricsSystem ms, ContainerId containerId, long flushPeriodMs) {
  this.recordInfo =
      info(sourceName(containerId), RECORD_INFO.description());
  this.registry = new MetricsRegistry(recordInfo);
  this.metricsSystem = ms;
  this.containerId = containerId;
  this.flushPeriodMs = flushPeriodMs;
  scheduleTimerTaskIfRequired();

  this.pMemMBsStat = registry.newStat(
      PMEM_USAGE_METRIC_NAME, "Physical memory stats", "Usage", "MBs", true);
  this.cpuCoreUsagePercent = registry.newStat(
      PHY_CPU_USAGE_METRIC_NAME, "Physical Cpu core percent usage stats",
      "Usage", "Percents", true);
  this.milliVcoresUsed = registry.newStat(
      VCORE_USAGE_METRIC_NAME, "1000 times Vcore usage", "Usage",
      "MilliVcores", true);
  this.pMemLimitMbs = registry.newGauge(
      PMEM_LIMIT_METRIC_NAME, "Physical memory limit in MBs", 0);
  this.vMemLimitMbs = registry.newGauge(
      VMEM_LIMIT_METRIC_NAME, "Virtual memory limit in MBs", 0);
  this.cpuVcoreLimit = registry.newGauge(
      VCORE_LIMIT_METRIC_NAME, "CPU limit in number of vcores", 0);
}
 
Example #10
Source File: FSQueueMetrics.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public synchronized 
static FSQueueMetrics forQueue(String queueName, Queue parent,
    boolean enableUserMetrics, Configuration conf) {
  MetricsSystem ms = DefaultMetricsSystem.instance();
  QueueMetrics metrics = queueMetrics.get(queueName);
  if (metrics == null) {
    metrics = new FSQueueMetrics(ms, queueName, parent, enableUserMetrics, conf)
        .tag(QUEUE_INFO, queueName);
    
    // Register with the MetricsSystems
    if (ms != null) {
      metrics = ms.register(
              sourceName(queueName).toString(), 
              "Metrics for queue: " + queueName, metrics);
    }
    queueMetrics.put(queueName, metrics);
  }

  return (FSQueueMetrics)metrics;
}
 
Example #11
Source File: QueueMetrics.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public synchronized 
static QueueMetrics forQueue(MetricsSystem ms, String queueName,
                                    Queue parent, boolean enableUserMetrics,
		      Configuration conf) {
  QueueMetrics metrics = queueMetrics.get(queueName);
  if (metrics == null) {
    metrics =
        new QueueMetrics(ms, queueName, parent, enableUserMetrics, conf).
        tag(QUEUE_INFO, queueName);
    
    // Register with the MetricsSystems
    if (ms != null) {
      metrics = 
          ms.register(
              sourceName(queueName).toString(), 
              "Metrics for queue: " + queueName, metrics);
    }
    queueMetrics.put(queueName, metrics);
  }

  return metrics;
}
 
Example #12
Source File: TestResourceTrackerService.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@After
public void tearDown() {
  if (hostFile != null && hostFile.exists()) {
    hostFile.delete();
  }

  ClusterMetrics.destroy();
  if (rm != null) {
    rm.stop();
  }

  MetricsSystem ms = DefaultMetricsSystem.instance();
  if (ms.getSource("ClusterMetrics") != null) {
    DefaultMetricsSystem.shutdown();
  }
}
 
Example #13
Source File: TestResourceTrackerService.java    From big-c with Apache License 2.0 6 votes vote down vote up
@After
public void tearDown() {
  if (hostFile != null && hostFile.exists()) {
    hostFile.delete();
  }

  ClusterMetrics.destroy();
  if (rm != null) {
    rm.stop();
  }

  MetricsSystem ms = DefaultMetricsSystem.instance();
  if (ms.getSource("ClusterMetrics") != null) {
    DefaultMetricsSystem.shutdown();
  }
}
 
Example #14
Source File: FSQueueMetrics.java    From big-c with Apache License 2.0 6 votes vote down vote up
public synchronized 
static FSQueueMetrics forQueue(String queueName, Queue parent,
    boolean enableUserMetrics, Configuration conf) {
  MetricsSystem ms = DefaultMetricsSystem.instance();
  QueueMetrics metrics = queueMetrics.get(queueName);
  if (metrics == null) {
    metrics = new FSQueueMetrics(ms, queueName, parent, enableUserMetrics, conf)
        .tag(QUEUE_INFO, queueName);
    
    // Register with the MetricsSystems
    if (ms != null) {
      metrics = ms.register(
              sourceName(queueName).toString(), 
              "Metrics for queue: " + queueName, metrics);
    }
    queueMetrics.put(queueName, metrics);
  }

  return (FSQueueMetrics)metrics;
}
 
Example #15
Source File: HadoopMetrics2Reporter.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private HadoopMetrics2Reporter(MetricRegistry registry, TimeUnit rateUnit, TimeUnit durationUnit,
        MetricFilter filter, MetricsSystem metrics2System, String jmxContext, String description, String recordName,
        String context) {
    super(registry, "hadoop-metrics2-reporter", filter, rateUnit, durationUnit);
    this.metrics2Registry = new MetricsRegistry(Interns.info(jmxContext, description));
    this.metrics2System = metrics2System;
    this.recordName = recordName;
    this.context = context;

    // These could really be Collection.emptyMap(), but this makes testing a bit easier.
    this.dropwizardGauges = EMPTY_GAUGE_MAP;
    this.dropwizardCounters = EMPTY_COUNTER_MAP;
    this.dropwizardHistograms = EMPTY_HISTOGRAM_MAP;
    this.dropwizardMeters = EMPTY_METER_MAP;
    this.dropwizardTimers = EMPTY_TIMER_MAP;

    // Register this source with the Metrics2 system.
    // Make sure this is the last thing done as getMetrics() can be called at any time after.
    this.metrics2System.register(Objects.requireNonNull(jmxContext), Objects.requireNonNull(description), this);
}
 
Example #16
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 #17
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 #18
Source File: SharedCacheUploaderMetrics.java    From big-c with Apache License 2.0 5 votes vote down vote up
static SharedCacheUploaderMetrics create() {
  MetricsSystem ms = DefaultMetricsSystem.instance();

  SharedCacheUploaderMetrics metrics =
      new SharedCacheUploaderMetrics();
  ms.register("SharedCacheUploaderRequests", null, metrics);
  return metrics;
}
 
Example #19
Source File: CleanerMetrics.java    From big-c with Apache License 2.0 5 votes vote down vote up
static CleanerMetrics create() {
  MetricsSystem ms = DefaultMetricsSystem.instance();

  CleanerMetrics metricObject = new CleanerMetrics();
  MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(metricObject);
  final MetricsSource s = sb.build();
  ms.register("cleaner", "The cleaner service of truly shared cache", s);
  metricObject.metricSource = s;
  return metricObject;
}
 
Example #20
Source File: HddsServerUtil.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize hadoop metrics system for Ozone servers.
 * @param configuration OzoneConfiguration to use.
 * @param serverName    The logical name of the server components.
 */
public static MetricsSystem initializeMetrics(
    OzoneConfiguration configuration, String serverName) {
  MetricsSystem metricsSystem = DefaultMetricsSystem.initialize(serverName);
  try {
    JvmMetrics.create(serverName,
        configuration.get(DFSConfigKeysLegacy.DFS_METRICS_SESSION_ID_KEY),
        DefaultMetricsSystem.instance());
  } catch (MetricsException e) {
    LOG.info("Metrics source JvmMetrics already added to DataNode.");
  }
  return metricsSystem;
}
 
Example #21
Source File: OzoneManagerDoubleBufferMetrics.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
public synchronized static OzoneManagerDoubleBufferMetrics create() {
  if (instance != null) {
    return instance;
  } else {
    MetricsSystem ms = DefaultMetricsSystem.instance();
    OzoneManagerDoubleBufferMetrics omDoubleBufferMetrics =
        ms.register(SOURCE_NAME,
            "OzoneManager DoubleBuffer Metrics",
            new OzoneManagerDoubleBufferMetrics());
    instance = omDoubleBufferMetrics;
    return omDoubleBufferMetrics;
  }
}
 
Example #22
Source File: MetricsSystemImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Initialized the metrics system with a prefix.
 * @param prefix  the system will look for configs with the prefix
 * @return the metrics system object itself
 */
@Override
public synchronized MetricsSystem init(String prefix) {
  if (monitoring && !DefaultMetricsSystem.inMiniClusterMode()) {
    LOG.warn(this.prefix +" metrics system already initialized!");
    return this;
  }
  this.prefix = checkNotNull(prefix, "prefix");
  ++refCount;
  if (monitoring) {
    // in mini cluster mode
    LOG.info(this.prefix +" metrics system started (again)");
    return this;
  }
  switch (initMode()) {
    case NORMAL:
      try { start(); }
      catch (MetricsConfigException e) {
        // Configuration errors (e.g., typos) should not be fatal.
        // We can always start the metrics system later via JMX.
        LOG.warn("Metrics system not started: "+ e.getMessage());
        LOG.debug("Stacktrace: ", e);
      }
      break;
    case STANDBY:
      LOG.info(prefix +" metrics system started in standby mode");
  }
  initSystemMBean();
  return this;
}
 
Example #23
Source File: TestContainerMetrics.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainerMetricsFlow() throws InterruptedException {
  final String ERR = "Error in number of records";

  // Create a dummy MetricsSystem
  MetricsSystem system = mock(MetricsSystem.class);
  doReturn(this).when(system).register(anyString(), anyString(), any());

  MetricsCollectorImpl collector = new MetricsCollectorImpl();
  ContainerId containerId = mock(ContainerId.class);
  ContainerMetrics metrics = ContainerMetrics.forContainer(containerId, 100);

  metrics.recordMemoryUsage(1024);
  metrics.getMetrics(collector, true);
  assertEquals(ERR, 0, collector.getRecords().size());

  Thread.sleep(110);
  metrics.getMetrics(collector, true);
  assertEquals(ERR, 1, collector.getRecords().size());
  collector.clear();

  Thread.sleep(110);
  metrics.getMetrics(collector, true);
  assertEquals(ERR, 1, collector.getRecords().size());
  collector.clear();

  metrics.finished();
  metrics.getMetrics(collector, true);
  assertEquals(ERR, 1, collector.getRecords().size());
  collector.clear();

  metrics.getMetrics(collector, true);
  assertEquals(ERR, 0, collector.getRecords().size());

  Thread.sleep(110);
  metrics.getMetrics(collector, true);
  assertEquals(ERR, 0, collector.getRecords().size());
}
 
Example #24
Source File: StandaloneExample.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    final MetricRegistry metrics = new MetricRegistry();

    final HadoopMetrics2Reporter metrics2Reporter = HadoopMetrics2Reporter.forRegistry(metrics).build(
            DefaultMetricsSystem.initialize("StandaloneTest"), // The application-level name
            "Test", // Component name
            "Test", // Component description
            "Test"); // Name for each metric record
    final ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metrics).build();

    MetricsSystem metrics2 = DefaultMetricsSystem.instance();
    // Writes to stdout without a filename configuration
    // Will be invoked every 10seconds by default
    FileSink sink = new FileSink();
    metrics2.register("filesink", "filesink", sink);
    sink.init(new SubsetConfiguration(null, null) {
        public String getString(String key) {
            if (key.equals("filename")) {
                return null;
            }
            return super.getString(key);
        }
    });

    // How often should the dropwizard reporter be invoked
    metrics2Reporter.start(500, TimeUnit.MILLISECONDS);
    // How often will the dropwziard metrics be logged to the console
    consoleReporter.start(2, TimeUnit.SECONDS);

    generateMetrics(metrics, 5000, 25, TimeUnit.MILLISECONDS, metrics2Reporter, 10);
}
 
Example #25
Source File: ProxyMetrics.java    From nnproxy with Apache License 2.0 5 votes vote down vote up
public static ProxyMetrics create(Configuration conf) {
    String sessionId = conf.get(DFSConfigKeys.DFS_METRICS_SESSION_ID_KEY);
    String processName = "NNPROXY";
    MetricsSystem ms = DefaultMetricsSystem.instance();
    JvmMetrics jm = JvmMetrics.create(processName, sessionId, ms);

    return ms.register(new ProxyMetrics(processName, sessionId, jm));
}
 
Example #26
Source File: QueueMetrics.java    From big-c with Apache License 2.0 5 votes vote down vote up
protected QueueMetrics(MetricsSystem ms, String queueName, Queue parent, 
      boolean enableUserMetrics, Configuration conf) {
  registry = new MetricsRegistry(RECORD_INFO);
  this.queueName = queueName;
  this.parent = parent != null ? parent.getMetrics() : null;
  this.users = enableUserMetrics ? new HashMap<String, QueueMetrics>()
                                 : null;
  metricsSystem = ms;
  this.conf = conf;
  runningTime = buildBuckets(conf);
}
 
Example #27
Source File: ContainerMetrics.java    From hadoop with Apache License 2.0 5 votes vote down vote up
ContainerMetrics(
    MetricsSystem ms, ContainerId containerId, long flushPeriodMs) {
  this.recordInfo =
      info(sourceName(containerId), RECORD_INFO.description());
  this.registry = new MetricsRegistry(recordInfo);
  this.metricsSystem = ms;
  this.containerId = containerId;
  this.flushPeriodMs = flushPeriodMs;
  scheduleTimerTaskIfRequired();

  this.pMemMBsStat = registry.newStat(
      PMEM_USAGE_METRIC_NAME, "Physical memory stats", "Usage", "MBs", true);
  this.cpuCoreUsagePercent = registry.newStat(
      PHY_CPU_USAGE_METRIC_NAME, "Physical Cpu core percent usage stats",
      "Usage", "Percents", true);
  this.milliVcoresUsed = registry.newStat(
      VCORE_USAGE_METRIC_NAME, "1000 times Vcore usage", "Usage",
      "MilliVcores", true);
  this.pMemLimitMbs = registry.newGauge(
      PMEM_LIMIT_METRIC_NAME, "Physical memory limit in MBs", 0);
  this.vMemLimitMbs = registry.newGauge(
      VMEM_LIMIT_METRIC_NAME, "Virtual memory limit in MBs", 0);
  this.cpuVcoreLimit = registry.newGauge(
      VCORE_LIMIT_METRIC_NAME, "CPU limit in number of vcores", 0);
  this.gpuGcoreLimit = registry.newGauge(
      GCORE_LIMIT_METRIC_NAME, "GPU limit in number of gcores", 0);
}
 
Example #28
Source File: QueueMetrics.java    From hadoop with Apache License 2.0 5 votes vote down vote up
protected QueueMetrics(MetricsSystem ms, String queueName, Queue parent, 
      boolean enableUserMetrics, Configuration conf) {
  registry = new MetricsRegistry(RECORD_INFO);
  this.queueName = queueName;
  this.parent = parent != null ? parent.getMetrics() : null;
  this.users = enableUserMetrics ? new HashMap<String, QueueMetrics>()
                                 : null;
  metricsSystem = ms;
  this.conf = conf;
  runningTime = buildBuckets(conf);
}
 
Example #29
Source File: TestContainerMetrics.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainerMetricsFlow() throws InterruptedException {
  final String ERR = "Error in number of records";

  // Create a dummy MetricsSystem
  MetricsSystem system = mock(MetricsSystem.class);
  doReturn(this).when(system).register(anyString(), anyString(), any());

  MetricsCollectorImpl collector = new MetricsCollectorImpl();
  ContainerId containerId = mock(ContainerId.class);
  ContainerMetrics metrics = ContainerMetrics.forContainer(containerId, 100);

  metrics.recordMemoryUsage(1024);
  metrics.getMetrics(collector, true);
  assertEquals(ERR, 0, collector.getRecords().size());

  Thread.sleep(110);
  metrics.getMetrics(collector, true);
  assertEquals(ERR, 1, collector.getRecords().size());
  collector.clear();

  Thread.sleep(110);
  metrics.getMetrics(collector, true);
  assertEquals(ERR, 1, collector.getRecords().size());
  collector.clear();

  metrics.finished();
  metrics.getMetrics(collector, true);
  assertEquals(ERR, 1, collector.getRecords().size());
  collector.clear();

  metrics.getMetrics(collector, true);
  assertEquals(ERR, 0, collector.getRecords().size());

  Thread.sleep(110);
  metrics.getMetrics(collector, true);
  assertEquals(ERR, 0, collector.getRecords().size());
}
 
Example #30
Source File: ClusterMetrics.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static void registerMetrics() {
  registry = new MetricsRegistry(RECORD_INFO);
  registry.tag(RECORD_INFO, "ResourceManager");
  MetricsSystem ms = DefaultMetricsSystem.instance();
  if (ms != null) {
    ms.register("ClusterMetrics", "Metrics for the Yarn Cluster", INSTANCE);
  }
}