@Override
  public void start(CoprocessorEnvironment env) throws IOException {
    // start for the MasterObserver will be called only once in the lifetime of the
    // server. We will construct and register all metrics that we will track across method
    // invocations.

    if (env instanceof MasterCoprocessorEnvironment) {
      // Obtain the MetricRegistry for the Master. Metrics from this registry will be reported
      // at the master level per-server.
      MetricRegistry registry = ((MasterCoprocessorEnvironment) env).getMetricRegistryForMaster();

      if (createTableTimer == null) {
        // Create a new Counter, or get the already registered counter.
        // It is much better to only call this once and save the Counter as a class field instead
        // of creating the counter every time a coprocessor method is invoked. This will negate
        // any performance bottleneck coming from map lookups tracking metrics in the registry.
        createTableTimer = registry.timer("CreateTable");

        // on stop(), we can remove these registered metrics via calling registry.remove(). But
        // it is not needed for coprocessors at the master level. If coprocessor is stopped,
        // the server is stopping anyway, so there will not be any resource leaks.
      }

      if (disableTableCounter == null) {
        disableTableCounter = registry.counter("DisableTable");
      }

      // Register a custom gauge. The Gauge object will be registered in the metrics registry and
      // periodically the getValue() is invoked to obtain the snapshot.
      registry.register("totalMemory", new Gauge<Long>() {
        @Override
        public Long getValue() {
          return getTotalMemory();
        }
      });

      // Register a custom gauge using Java-8 lambdas (Supplier converted into Gauge)
      registry.register("maxMemory", this::getMaxMemory);
    }
  }
Returns the max memory of the process. We will use this to define a gauge metric
hbase-examples/src/main/java/org/apache/hadoop/hbase/coprocessor/example/ExampleMasterObserverWithMetrics.java