@Override
  public void getMetrics(MetricsCollector metricsCollector, boolean all) {

    MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName);

    // masterWrapper can be null because this function is called inside of init.
    // If the master is already stopped or has initiated a shutdown, no point in registering the
    // metrics again.
    if (masterWrapper != null && masterWrapper.isRunning()) {

      // Pair<online region number, offline region number>
      PairOfSameType<Integer> regionNumberPair = masterWrapper.getRegionCounts();

      metricsRecordBuilder
        .addGauge(Interns.info(MERGE_PLAN_COUNT_NAME, MERGE_PLAN_COUNT_DESC),
          masterWrapper.getMergePlanCount())
        .addGauge(Interns.info(SPLIT_PLAN_COUNT_NAME, SPLIT_PLAN_COUNT_DESC),
          masterWrapper.getSplitPlanCount())
        .addGauge(Interns.info(MASTER_ACTIVE_TIME_NAME, MASTER_ACTIVE_TIME_DESC),
          masterWrapper.getActiveTime())
        .addGauge(Interns.info(MASTER_START_TIME_NAME, MASTER_START_TIME_DESC),
          masterWrapper.getStartTime())
        .addGauge(Interns.info(MASTER_FINISHED_INITIALIZATION_TIME_NAME,
          MASTER_FINISHED_INITIALIZATION_TIME_DESC), masterWrapper.getMasterInitializationTime())
        .addGauge(Interns.info(AVERAGE_LOAD_NAME, AVERAGE_LOAD_DESC),
          masterWrapper.getAverageLoad())
        .addGauge(Interns.info(ONLINE_REGION_COUNT_NAME, ONLINE_REGION_COUNT_DESC),
          regionNumberPair.getFirst())
        .addGauge(Interns.info(OFFLINE_REGION_COUNT_NAME, OFFLINE_REGION_COUNT_DESC),
          regionNumberPair.getSecond())
        .tag(Interns.info(LIVE_REGION_SERVERS_NAME, LIVE_REGION_SERVERS_DESC),
          masterWrapper.getRegionServers())
        .addGauge(Interns.info(NUM_REGION_SERVERS_NAME, NUMBER_OF_REGION_SERVERS_DESC),
          masterWrapper.getNumRegionServers())
        .tag(Interns.info(DEAD_REGION_SERVERS_NAME, DEAD_REGION_SERVERS_DESC),
          masterWrapper.getDeadRegionServers())
        .addGauge(Interns.info(NUM_DEAD_REGION_SERVERS_NAME, NUMBER_OF_DEAD_REGION_SERVERS_DESC),
          masterWrapper.getNumDeadRegionServers())
        .tag(Interns.info(DRAINING_REGION_SERVER_NAME, DRAINING_REGION_SERVER_DESC),
          masterWrapper.getDrainingRegionServers())
        .addGauge(
          Interns.info(NUM_DRAINING_REGION_SERVERS_NAME, NUMBER_OF_DRAINING_REGION_SERVERS_DESC),
          masterWrapper.getNumDrainingRegionServers())
        .tag(Interns.info(ZOOKEEPER_QUORUM_NAME, ZOOKEEPER_QUORUM_DESC),
          masterWrapper.getZookeeperQuorum())
        .tag(Interns.info(SERVER_NAME_NAME, SERVER_NAME_DESC), masterWrapper.getServerName())
        .tag(Interns.info(CLUSTER_ID_NAME, CLUSTER_ID_DESC), masterWrapper.getClusterId())
        .tag(Interns.info(IS_ACTIVE_MASTER_NAME, IS_ACTIVE_MASTER_DESC),
          String.valueOf(masterWrapper.getIsActiveMaster()))
        .addGauge(Interns.info(OLD_WAL_DIR_SIZE_NAME, OLD_WAL_DIR_SIZE_DESC),
          masterWrapper.getOldWALsDirSize());
    }

    metricsRegistry.snapshot(metricsRecordBuilder, all);
    if (metricsAdapter != null) {
      metricsAdapter.snapshotAllMetrics(registry, metricsRecordBuilder);
    }
  }
Hadoop2 implementation of MetricsMasterSource. Implements BaseSource through BaseSourceImpl,
following the pattern
hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceImpl.java