private void doRun() {
    if (stopped.get()) {
      executor.stop();
      return;
    }
    if (LOG.isTraceEnabled()) {
      LOG.trace("doRun called: " + registeredSources);
    }

    Collection<MetricRegistry> registries = MetricRegistries.global().getMetricRegistries();
    for (MetricRegistry registry : registries) {
      MetricRegistryInfo info = registry.getMetricRegistryInfo();

      LOG.trace("MetricRegistryInfo : " + info.getMetricsName());
      if (info.isExistingSource()) {
        // If there is an already existing BaseSource for this MetricRegistry, skip it here. These
        // types of registries are there only due to existing BaseSource implementations in the
        // source code (like MetricsRegionServer, etc). This is to make sure that we can transition
        // iteratively to the new hbase-metrics system. These type of MetricRegistry metrics will be
        // exported from the BaseSource.getMetrics() call directly because there is already a
        // MetricRecordBuilder there (see MetricsRegionServerSourceImpl).
        continue;
      }

      if (!registeredSources.containsKey(info)) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Registering adapter for the MetricRegistry: " + info.getMetricsJmxContext());
        }
        // register this as a MetricSource under different JMX Context'es.
        MetricsSourceAdapter adapter = new MetricsSourceAdapter(registry);
        LOG.info("Registering " + info.getMetricsJmxContext() + " " + info.getMetricsDescription());
        DefaultMetricsSystem.instance().register(info.getMetricsJmxContext(),
          info.getMetricsDescription(), adapter);
        registeredSources.put(info, adapter);
        // next collection will collect the newly registered MetricSource. Doing this here leads to
        // ConcurrentModificationException.
      }
    }

    boolean removed = false;
    // Remove registered sources if it is removed from the global registry
    for (Iterator<Entry<MetricRegistryInfo, MetricsSourceAdapter>> it =
      registeredSources.entrySet().iterator(); it.hasNext();) {
      Entry<MetricRegistryInfo, MetricsSourceAdapter> entry = it.next();
      MetricRegistryInfo info = entry.getKey();
      Optional<MetricRegistry> found = MetricRegistries.global().get(info);
      if (!found.isPresent()) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Removing adapter for the MetricRegistry: " + info.getMetricsJmxContext());
        }
        synchronized (DefaultMetricsSystem.instance()) {
          DefaultMetricsSystem.instance().unregisterSource(info.getMetricsJmxContext());
          helper.removeSourceName(info.getMetricsJmxContext());
          helper.removeObjectName(info.getMetricsJmxContext());
          it.remove();
          removed = true;
        }
      }
    }
    if (removed) {
      JmxCacheBuster.clearJmxCache();
    }
  }
Make sure that this global MetricSource for hbase-metrics module based metrics are initialized.
This should be called only once.
hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/impl/GlobalMetricRegistriesAdapter.java