Java Code Examples for org.apache.hadoop.hbase.metrics.MetricRegistry#timer()

The following examples show how to use org.apache.hadoop.hbase.metrics.MetricRegistry#timer() . 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: TestCoprocessorMetrics.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  if (env instanceof MasterCoprocessorEnvironment) {
    MetricRegistry registry =
        ((MasterCoprocessorEnvironment) env).getMetricRegistryForMaster();

    createTableTimer  = registry.timer("CreateTable");
  }
}
 
Example 2
Source File: TestCoprocessorMetrics.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  super.start(env);

  if (env instanceof RegionCoprocessorEnvironment) {
    MetricRegistry registry =
        ((RegionCoprocessorEnvironment) env).getMetricRegistryForRegionServer();

    if (endpointExecution == null) {
      endpointExecution = registry.timer("EndpointExecution");
    }
  }
}
 
Example 3
Source File: ExampleRegionObserverWithMetrics.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  // start for the RegionServerObserver 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 RegionCoprocessorEnvironment) {
    // Obtain the MetricRegistry for the RegionServer. Metrics from this registry will be reported
    // at the region server level per-regionserver.
    MetricRegistry registry =
        ((RegionCoprocessorEnvironment) env).getMetricRegistryForRegionServer();
    observer = new ExampleRegionObserver();

    if (preGetCounter == 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.
      // Returned counter instance is shared by all coprocessors of the same class in the same
      // region server.
      preGetCounter = registry.counter("preGetRequests");
    }

    if (costlyOperationTimer == null) {
      // Create a Timer to track execution times for the costly operation.
      costlyOperationTimer = registry.timer("costlyOperation");
    }

    if (flushCounter == null) {
      // Track the number of flushes that have completed
      flushCounter = registry.counter("flushesCompleted");
    }

    if (filesCompactedCounter == null) {
      // Track the number of files that were compacted (many files may be rewritten in a single
      // compaction).
      filesCompactedCounter = registry.counter("filesCompacted");
    }
  }
}
 
Example 4
Source File: ExampleMasterObserverWithMetrics.java    From hbase with Apache License 2.0 4 votes vote down vote up
@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);
  }
}