类org.apache.hadoop.hbase.metrics.MetricRegistry源码实例Demo

下面列出了怎么用org.apache.hadoop.hbase.metrics.MetricRegistry的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hbase   文件: TestCoprocessorMetrics.java
@Test
public void testMasterObserver() throws IOException {
  // Find out the MetricRegistry used by the CP using the global registries
  MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForMasterCoprocessor(
      CustomMasterObserver.class.getName());
  Optional<MetricRegistry> registry =  MetricRegistries.global().get(info);
  assertTrue(registry.isPresent());

  Optional<Metric> metric = registry.get().get("CreateTable");
  assertTrue(metric.isPresent());

  try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
       Admin admin = connection.getAdmin()) {

    Timer createTableTimer = (Timer)metric.get();
    long prevCount = createTableTimer.getHistogram().getCount();
    LOG.info("Creating table");
    TableDescriptorBuilder tableDescriptorBuilder =
      TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
    ColumnFamilyDescriptor columnFamilyDescriptor =
      ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("foo")).build();
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    admin.createTable(tableDescriptorBuilder.build());
    assertEquals(1, createTableTimer.getHistogram().getCount() - prevCount);
  }
}
 
源代码2 项目: hbase   文件: HBaseMetrics2HadoopMetricsAdapter.java
/**
 * Iterates over the MetricRegistry and adds them to the {@code builder}.
 *
 * @param builder A record builder
 */
public void snapshotAllMetrics(MetricRegistry metricRegistry, MetricsRecordBuilder builder) {
  Map<String, Metric> metrics = metricRegistry.getMetrics();

  for (Map.Entry<String, Metric> e: metrics.entrySet()) {
    // Always capitalize the name
    String name = StringUtils.capitalize(e.getKey());
    Metric metric = e.getValue();

    if (metric instanceof Gauge) {
      addGauge(name, (Gauge<?>) metric, builder);
    } else if (metric instanceof Counter) {
      addCounter(name, (Counter)metric, builder);
    } else if (metric instanceof Histogram) {
      addHistogram(name, (Histogram)metric, builder);
    } else if (metric instanceof Meter) {
      addMeter(name, (Meter)metric, builder);
    } else if (metric instanceof Timer) {
      addTimer(name, (Timer)metric, builder);
    } else {
      LOG.info("Ignoring unknown Metric class " + metric.getClass().getName());
    }
  }
}
 
源代码3 项目: phoenix   文件: GlobalMetricRegistriesAdapter.java
private void snapshotAllMetrics(MetricRegistry metricRegistry, MetricsRecordBuilder builder) {
    Map<String, Metric> metrics = metricRegistry.getMetrics();
    Iterator iterator = metrics.entrySet().iterator();

    while(iterator.hasNext()) {
        Entry<String, Metric> e = (Entry)iterator.next();
        String name = StringUtils.capitalize(e.getKey());
        Metric metric = e.getValue();
        if (metric instanceof Gauge) {
            this.addGauge(name, (Gauge)metric, builder);
        } else if (metric instanceof Counter) {
            this.addCounter(name, (Counter)metric, builder);
        } else if (metric instanceof Histogram) {
            this.addHistogram(name, (Histogram)metric, builder);
        } else if (metric instanceof Meter) {
            this.addMeter(name, (Meter)metric, builder);
        } else if (metric instanceof Timer) {
            this.addTimer(name, (Timer)metric, builder);
        } else {
            LOGGER.info("Ignoring unknown Metric class " + metric.getClass().getName());
        }
    }
}
 
源代码4 项目: hbase   文件: TestCoprocessorMetrics.java
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  if (env instanceof MasterCoprocessorEnvironment) {
    MetricRegistry registry =
        ((MasterCoprocessorEnvironment) env).getMetricRegistryForMaster();

    createTableTimer  = registry.timer("CreateTable");
  }
}
 
源代码5 项目: hbase   文件: TestCoprocessorMetrics.java
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  if (env instanceof RegionServerCoprocessorEnvironment) {
    MetricRegistry registry =
        ((RegionServerCoprocessorEnvironment) env).getMetricRegistryForRegionServer();

    if (rollWALCounter == null) {
      rollWALCounter = registry.counter("rollWALRequests");
    }
  }
}
 
源代码6 项目: hbase   文件: TestCoprocessorMetrics.java
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  if (env instanceof WALCoprocessorEnvironment) {
    MetricRegistry registry =
        ((WALCoprocessorEnvironment) env).getMetricRegistryForRegionServer();

    if (walEditsCount == null) {
      walEditsCount = registry.counter("walEditsCount");
    }
  }
}
 
源代码7 项目: hbase   文件: TestCoprocessorMetrics.java
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  if (env instanceof RegionCoprocessorEnvironment) {
    MetricRegistry registry =
        ((RegionCoprocessorEnvironment) env).getMetricRegistryForRegionServer();

    if (preGetCounter == null) {
      preGetCounter = registry.counter("preGetRequests");
    }
  }
}
 
源代码8 项目: hbase   文件: TestCoprocessorMetrics.java
@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");
    }
  }
}
 
源代码9 项目: hbase   文件: TestCoprocessorMetrics.java
@Test
public void testWALObserver() throws IOException {
  // Find out the MetricRegistry used by the CP using the global registries
  MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForWALCoprocessor(
      CustomWALObserver.class.getName());

  Optional<MetricRegistry> registry =  MetricRegistries.global().get(info);
  assertTrue(registry.isPresent());

  Optional<Metric> metric = registry.get().get("walEditsCount");
  assertTrue(metric.isPresent());

  try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
       Admin admin = connection.getAdmin()) {
    TableDescriptorBuilder tableDescriptorBuilder =
      TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
    ColumnFamilyDescriptor columnFamilyDescriptor =
      ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("foo")).build();
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    admin.createTable(tableDescriptorBuilder.build());

    Counter rollWalRequests = (Counter)metric.get();
    long prevCount = rollWalRequests.getCount();
    assertTrue(prevCount > 0);

    try (Table table = connection.getTable(TableName.valueOf(name.getMethodName()))) {
      table.put(new Put(foo).addColumn(foo, foo, foo));
    }

    assertEquals(1, rollWalRequests.getCount() - prevCount);
  }
}
 
源代码10 项目: hbase   文件: TestCoprocessorMetrics.java
/**
 * Helper for below tests
 */
private void assertPreGetRequestsCounter(Class<?> coprocClass) {
  // Find out the MetricRegistry used by the CP using the global registries
  MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForRegionCoprocessor(
      coprocClass.getName());

  Optional<MetricRegistry> registry =  MetricRegistries.global().get(info);
  assertTrue(registry.isPresent());

  Optional<Metric> metric = registry.get().get("preGetRequests");
  assertTrue(metric.isPresent());

  Counter preGetRequests = (Counter)metric.get();
  assertEquals(2, preGetRequests.getCount());
}
 
源代码11 项目: hbase   文件: HBaseMetrics2HadoopMetricsAdapter.java
/**
 * Iterates over the MetricRegistry and adds them to the {@code collector}.
 *
 * @param collector A metrics collector
 */
public void snapshotAllMetrics(MetricRegistry metricRegistry,
                               MetricsCollector collector) {
  MetricRegistryInfo info = metricRegistry.getMetricRegistryInfo();
  MetricsRecordBuilder builder = collector.addRecord(Interns.info(info.getMetricsName(),
      info.getMetricsDescription()));
  builder.setContext(info.getMetricsContext());

  snapshotAllMetrics(metricRegistry, builder);
}
 
源代码12 项目: hbase   文件: ExampleRegionObserverWithMetrics.java
@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");
    }
  }
}
 
源代码13 项目: phoenix   文件: GlobalMetricRegistriesAdapter.java
public void registerMetricRegistry(MetricRegistry registry) {
    if (registry == null) {
        LOGGER.warn("Registry cannot be registered with Hadoop Metrics 2 since it is null.");
        return;
    }

    HBaseMetrics2HadoopMetricsAdapter adapter = new HBaseMetrics2HadoopMetricsAdapter(registry);
    adapter.registerToDefaultMetricsSystem();
}
 
源代码14 项目: phoenix   文件: GlobalMetricRegistriesAdapter.java
private void snapshotAllMetrics(MetricRegistry metricRegistry, MetricsCollector collector) {
    MetricRegistryInfo hbaseMetricRegistryInfo = metricRegistry.getMetricRegistryInfo();
    MetricsInfo hadoopMetricsInfo = Interns.info(hbaseMetricRegistryInfo.getMetricsName(), hbaseMetricRegistryInfo.getMetricsDescription());
    MetricsRecordBuilder builder = collector.addRecord(hadoopMetricsInfo);
    builder.setContext(hbaseMetricRegistryInfo.getMetricsContext());
    builder.tag(hadoopMetricsInfo, metricTag);
    this.snapshotAllMetrics(metricRegistry, builder);
}
 
源代码15 项目: pentaho-hadoop-shims   文件: HadoopShim.java
@Override
public Class[] getHbaseDependencyClasses() {
  return new Class[] {
    HConstants.class, org.apache.hadoop.hbase.protobuf.generated.ClientProtos.class,
    org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.class, Put.class,
    RpcServer.class, CompatibilityFactory.class, JobUtil.class, TableMapper.class, FastLongHistogram.class,
    Snapshot.class, ZooKeeper.class, Channel.class, Message.class, UnsafeByteOperations.class, Lists.class,
    Tracer.class, MetricRegistry.class, ArrayUtils.class, ObjectMapper.class, Versioned.class,
    JsonView.class, ZKWatcher.class, CacheLoader.class
  };
}
 
源代码16 项目: hbase   文件: MasterCoprocessorHost.java
@Override
public MetricRegistry getMetricRegistryForMaster() {
  return metricRegistry;
}
 
源代码17 项目: hbase   文件: MetricsCoprocessor.java
public static MetricRegistry createRegistryForMasterCoprocessor(String clazz) {
  return MetricRegistries.global().create(createRegistryInfoForMasterCoprocessor(clazz));
}
 
源代码18 项目: hbase   文件: MetricsCoprocessor.java
public static MetricRegistry createRegistryForRSCoprocessor(String clazz) {
  return MetricRegistries.global().create(createRegistryInfoForRSCoprocessor(clazz));
}
 
源代码19 项目: hbase   文件: MetricsCoprocessor.java
public static MetricRegistry createRegistryForRegionCoprocessor(String clazz) {
  return MetricRegistries.global().create(createRegistryInfoForRegionCoprocessor(clazz));
}
 
源代码20 项目: hbase   文件: MetricsCoprocessor.java
public static MetricRegistry createRegistryForWALCoprocessor(String clazz) {
  return MetricRegistries.global().create(createRegistryInfoForWALCoprocessor(clazz));
}
 
源代码21 项目: hbase   文件: MetricsCoprocessor.java
public static void removeRegistry(MetricRegistry registry) {
  if (registry == null) {
    return;
  }
  MetricRegistries.global().remove(registry.getMetricRegistryInfo());
}
 
源代码22 项目: hbase   文件: RegionServerCoprocessorHost.java
@Override
public MetricRegistry getMetricRegistryForRegionServer() {
  return metricRegistry;
}
 
源代码23 项目: hbase   文件: WALCoprocessorHost.java
@Override
public MetricRegistry getMetricRegistryForRegionServer() {
  return metricRegistry;
}
 
源代码24 项目: hbase   文件: RegionCoprocessorHost.java
@Override
public MetricRegistry getMetricRegistryForRegionServer() {
  return metricRegistry;
}
 
源代码25 项目: hbase   文件: TestCoprocessorMetrics.java
@Test
public void testRegionObserverAfterRegionClosed() throws IOException {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
       Admin admin = connection.getAdmin()) {
    admin.createTable(
      new TableDescriptorBuilder.ModifyableTableDescriptor(tableName)
        .setColumnFamily(
          new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(foo))
        // add the coprocessor for the region
        .setCoprocessor(CustomRegionObserver.class.getName()), new byte[][]{foo});
    // create with 2 regions
    try (Table table = connection.getTable(tableName)) {
      table.get(new Get(foo));
      table.get(new Get(foo)); // 2 gets
    }

    assertPreGetRequestsCounter(CustomRegionObserver.class);

    // close one of the regions
    try (RegionLocator locator = connection.getRegionLocator(tableName)) {
      HRegionLocation loc = locator.getRegionLocation(foo);
      admin.unassign(loc.getRegion().getEncodedNameAsBytes(), true);

      HRegionServer server = UTIL.getMiniHBaseCluster().getRegionServer(loc.getServerName());
      UTIL.waitFor(30000,
        () -> server.getOnlineRegion(loc.getRegion().getRegionName()) == null);
      assertNull(server.getOnlineRegion(loc.getRegion().getRegionName()));
    }

    // with only 1 region remaining, we should still be able to find the Counter
    assertPreGetRequestsCounter(CustomRegionObserver.class);

    // close the table
    admin.disableTable(tableName);

    MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForRegionCoprocessor(
        CustomRegionObserver.class.getName());

    // ensure that MetricRegistry is deleted
    Optional<MetricRegistry> registry =  MetricRegistries.global().get(info);
    assertFalse(registry.isPresent());
  }
}
 
源代码26 项目: hbase   文件: TestCoprocessorMetrics.java
@Test
public void testRegionObserverEndpoint() throws IOException, ServiceException {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
       Admin admin = connection.getAdmin()) {
    admin.createTable(
      new TableDescriptorBuilder.ModifyableTableDescriptor(tableName)
        .setColumnFamily(
          new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(foo))
        // add the coprocessor for the region
        .setCoprocessor(CustomRegionEndpoint.class.getName()));

    try (Table table = connection.getTable(tableName)) {
      List<Mutation> mutations = Lists.newArrayList(new Put(foo), new Put(bar));
      MutateRowsRequest.Builder mrmBuilder = MutateRowsRequest.newBuilder();

      for (Mutation mutation : mutations) {
        mrmBuilder.addMutationRequest(ProtobufUtil.toMutation(
            ClientProtos.MutationProto.MutationType.PUT, mutation));
      }

      CoprocessorRpcChannel channel = table.coprocessorService(bar);
      MultiRowMutationService.BlockingInterface service =
          MultiRowMutationService.newBlockingStub(channel);
      MutateRowsRequest mrm = mrmBuilder.build();
      service.mutateRows(null, mrm);
    }
  }

  // Find out the MetricRegistry used by the CP using the global registries
  MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForRegionCoprocessor(
      CustomRegionEndpoint.class.getName());

  Optional<MetricRegistry> registry =  MetricRegistries.global().get(info);
  assertTrue(registry.isPresent());

  Optional<Metric> metric = registry.get().get("EndpointExecution");
  assertTrue(metric.isPresent());

  Timer endpointExecutions = (Timer)metric.get();
  assertEquals(1, endpointExecutions.getHistogram().getCount());
}
 
源代码27 项目: hbase   文件: MetricRegistriesImpl.java
@Override
public MetricRegistry create(MetricRegistryInfo info) {
  return registries.put(info, () -> factory.create(info));
}
 
源代码28 项目: hbase   文件: MetricRegistriesImpl.java
@Override
public Optional<MetricRegistry> get(MetricRegistryInfo info) {
  return Optional.ofNullable(registries.get(info));
}
 
源代码29 项目: hbase   文件: MetricRegistriesImpl.java
@Override
public Collection<MetricRegistry> getMetricRegistries() {
  return Collections.unmodifiableCollection(registries.values());
}
 
源代码30 项目: hbase   文件: MetricRegistryFactoryImpl.java
@Override
public MetricRegistry create(MetricRegistryInfo info) {
  return new MetricRegistryImpl(info);
}
 
 类所在包
 类方法
 同包方法