Java Code Examples for org.apache.hadoop.metrics2.MetricsSystem

The following examples show how to use org.apache.hadoop.metrics2.MetricsSystem. These examples are extracted from open source projects. 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 Project: kylin   Source File: HadoopMetrics2Reporter.java    License: 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 2
Source Project: big-c   Source File: TestResourceTrackerService.java    License: 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 3
Source Project: big-c   Source File: QueueMetrics.java    License: 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 4
Source Project: hadoop-ozone   Source File: EventWatcher.java    License: 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 5
Source Project: hadoop-ozone   Source File: TestRocksDBStoreMBean.java    License: 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 6
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 7
Source Project: big-c   Source File: ContainerMetrics.java    License: 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 8
Source Project: hadoop   Source File: ContainerMetrics.java    License: 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 9
Source Project: hadoop   Source File: QueueMetrics.java    License: 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 10
Source Project: hadoop   Source File: FSQueueMetrics.java    License: 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 Project: big-c   Source File: FSQueueMetrics.java    License: 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 12
Source Project: hadoop   Source File: TestResourceTrackerService.java    License: 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 Project: hadoop   Source File: TestShuffleHandler.java    License: 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 14
Source Project: phoenix   Source File: Metrics.java    License: 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 15
Source Project: hadoop   Source File: TestMetricsSystemImpl.java    License: 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 16
Source Project: big-c   Source File: TestClusterMetrics.java    License: Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() {
  ClusterMetrics.destroy();

  MetricsSystem ms = DefaultMetricsSystem.instance();
  if (ms.getSource("ClusterMetrics") != null) {
    DefaultMetricsSystem.shutdown();
  }
}
 
Example 17
Source Project: big-c   Source File: ClusterMetrics.java    License: 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);
  }
}
 
Example 18
Source Project: kylin   Source File: HadoopMetrics2ReporterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    mockRegistry = mock(MetricRegistry.class);
    mockMetricsSystem = mock(MetricsSystem.class);

    recordName = "myserver";
    metrics2Reporter = HadoopMetrics2Reporter.forRegistry(mockRegistry).convertDurationsTo(TimeUnit.MILLISECONDS)
            .convertRatesTo(TimeUnit.SECONDS).build(mockMetricsSystem, "MyServer", "My Cool Server", recordName);
}
 
Example 19
Source Project: big-c   Source File: ClientSCMMetrics.java    License: Apache License 2.0 5 votes vote down vote up
static ClientSCMMetrics create() {
  MetricsSystem ms = DefaultMetricsSystem.instance();

  ClientSCMMetrics metrics = new ClientSCMMetrics();
  ms.register("clientRequests", null, metrics);
  return metrics;
}
 
Example 20
Source Project: big-c   Source File: TestContainerMetrics.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testContainerMetricsLimit() throws InterruptedException {
  final String ERR = "Error in number of records";

  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);

  int anyPmemLimit = 1024;
  int anyVmemLimit = 2048;
  int anyVcores = 10;
  String anyProcessId = "1234";

  metrics.recordResourceLimit(anyVmemLimit, anyPmemLimit, anyVcores);
  metrics.recordProcessId(anyProcessId);

  Thread.sleep(110);
  metrics.getMetrics(collector, true);
  assertEquals(ERR, 1, collector.getRecords().size());
  MetricsRecord record = collector.getRecords().get(0);

  MetricsRecords.assertTag(record, ContainerMetrics.PROCESSID_INFO.name(),
      anyProcessId);

  MetricsRecords.assertMetric(record, ContainerMetrics
      .PMEM_LIMIT_METRIC_NAME, anyPmemLimit);
  MetricsRecords.assertMetric(record, ContainerMetrics.VMEM_LIMIT_METRIC_NAME, anyVmemLimit);
  MetricsRecords.assertMetric(record, ContainerMetrics.VCORE_LIMIT_METRIC_NAME, anyVcores);

  collector.clear();
}
 
Example 21
Source Project: big-c   Source File: DataNodeMetrics.java    License: Apache License 2.0 5 votes vote down vote up
public static DataNodeMetrics create(Configuration conf, String dnName) {
  String sessionId = conf.get(DFSConfigKeys.DFS_METRICS_SESSION_ID_KEY);
  MetricsSystem ms = DefaultMetricsSystem.instance();
  JvmMetrics jm = JvmMetrics.create("DataNode", sessionId, ms);
  String name = "DataNodeActivity-"+ (dnName.isEmpty()
      ? "UndefinedDataNodeName"+ DFSUtil.getRandom().nextInt() 
          : dnName.replace(':', '-'));

  // Percentile measurement is off by default, by watching no intervals
  int[] intervals = 
      conf.getInts(DFSConfigKeys.DFS_METRICS_PERCENTILES_INTERVALS_KEY);
  
  return ms.register(name, null, new DataNodeMetrics(name, sessionId,
      intervals, jm));
}
 
Example 22
Source Project: hadoop-ozone   Source File: RocksDBStoreMBean.java    License: Apache License 2.0 5 votes vote down vote up
public static RocksDBStoreMBean create(Statistics statistics,
                                       String contextName) {

  RocksDBStoreMBean rocksDBStoreMBean = new RocksDBStoreMBean(
      statistics, contextName);
  MetricsSystem ms = DefaultMetricsSystem.instance();
  MetricsSource metricsSource = ms.getSource(rocksDBStoreMBean.contextName);
  if (metricsSource != null) {
    return (RocksDBStoreMBean)metricsSource;
  } else {
    return ms.register(rocksDBStoreMBean.contextName,
        "RocksDB Metrics",
        rocksDBStoreMBean);
  }
}
 
Example 23
Source Project: hadoop-ozone   Source File: HddsServerUtil.java    License: 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 24
Source Project: hadoop-ozone   Source File: TestPrometheusMetricsSink.java    License: 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 25
Source Project: big-c   Source File: TestMetricsSystemImpl.java    License: 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 26
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 27
Source Project: kylin-on-parquet-v2   Source File: StandaloneExample.java    License: 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 28
Source Project: big-c   Source File: QueueMetrics.java    License: 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 Project: hadoop   Source File: ContainerMetrics.java    License: 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 30
Source Project: hadoop   Source File: TestContainerMetrics.java    License: 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());
}