Java Code Examples for org.apache.hadoop.metrics2.MetricsCollector#addRecord()

The following examples show how to use org.apache.hadoop.metrics2.MetricsCollector#addRecord() . 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: SCMPipelineMetrics.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("SuspiciousMethodCalls")
public void getMetrics(MetricsCollector collector, boolean all) {
  MetricsRecordBuilder recordBuilder = collector.addRecord(SOURCE_NAME);
  numPipelineAllocated.snapshot(recordBuilder, true);
  numPipelineCreated.snapshot(recordBuilder, true);
  numPipelineCreationFailed.snapshot(recordBuilder, true);
  numPipelineDestroyed.snapshot(recordBuilder, true);
  numPipelineDestroyFailed.snapshot(recordBuilder, true);
  numPipelineReportProcessed.snapshot(recordBuilder, true);
  numPipelineReportProcessingFailed.snapshot(recordBuilder, true);
  numPipelineContainSameDatanodes.snapshot(recordBuilder, true);
  numBytesWritten
      .forEach((pid, metric) -> metric.snapshot(recordBuilder, true));
  numBlocksAllocated
      .forEach((pid, metric) -> metric.snapshot(recordBuilder, true));
}
 
Example 2
Source File: StartupProgressMetrics.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  StartupProgressView prog = startupProgress.createView();
  MetricsRecordBuilder builder = collector.addRecord(
    STARTUP_PROGRESS_METRICS_INFO);

  builder.addCounter(info("ElapsedTime", "overall elapsed time"),
    prog.getElapsedTime());
  builder.addGauge(info("PercentComplete", "overall percent complete"),
    prog.getPercentComplete());

  for (Phase phase: prog.getPhases()) {
    addCounter(builder, phase, "Count", " count", prog.getCount(phase));
    addCounter(builder, phase, "ElapsedTime", " elapsed time",
      prog.getElapsedTime(phase));
    addCounter(builder, phase, "Total", " total", prog.getTotal(phase));
    addGauge(builder, phase, "PercentComplete", " percent complete",
      prog.getPercentComplete(phase));
  }
}
 
Example 3
Source File: StartupProgressMetrics.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  StartupProgressView prog = startupProgress.createView();
  MetricsRecordBuilder builder = collector.addRecord(
    STARTUP_PROGRESS_METRICS_INFO);

  builder.addCounter(info("ElapsedTime", "overall elapsed time"),
    prog.getElapsedTime());
  builder.addGauge(info("PercentComplete", "overall percent complete"),
    prog.getPercentComplete());

  for (Phase phase: prog.getPhases()) {
    addCounter(builder, phase, "Count", " count", prog.getCount(phase));
    addCounter(builder, phase, "ElapsedTime", " elapsed time",
      prog.getElapsedTime(phase));
    addCounter(builder, phase, "Total", " total", prog.getTotal(phase));
    addGauge(builder, phase, "PercentComplete", " percent complete",
      prog.getPercentComplete(phase));
  }
}
 
Example 4
Source File: MetricsMasterQuotaSourceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder record = metricsCollector.addRecord(metricsRegistry.info());
  if (wrapper != null) {
    // Summarize the tables
    Map<String,Entry<Long,Long>> tableUsages = wrapper.getTableSpaceUtilization();
    String tableSummary = "[]";
    if (tableUsages != null && !tableUsages.isEmpty()) {
      tableSummary = generateJsonQuotaSummary(tableUsages.entrySet(), "table");
    }
    record.tag(Interns.info(TABLE_QUOTA_USAGE_NAME, TABLE_QUOTA_USAGE_DESC), tableSummary);

    // Summarize the namespaces
    String nsSummary = "[]";
    Map<String,Entry<Long,Long>> namespaceUsages = wrapper.getNamespaceSpaceUtilization();
    if (namespaceUsages != null && !namespaceUsages.isEmpty()) {
      nsSummary = generateJsonQuotaSummary(namespaceUsages.entrySet(), "namespace");
    }
    record.tag(Interns.info(NS_QUOTA_USAGE_NAME, NS_QUOTA_USAGE_DESC), nsSummary);
  }
  metricsRegistry.snapshot(record, all);
}
 
Example 5
Source File: MetricsMasterProcSourceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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 (masterWrapper != null) {
    metricsRecordBuilder
        .addGauge(Interns.info(NUM_MASTER_WALS_NAME, NUM_MASTER_WALS_DESC),
            masterWrapper.getNumWALFiles());
  }

  metricsRegistry.snapshot(metricsRecordBuilder, all);
  if(metricsAdapter != null) {
    metricsAdapter.snapshotAllMetrics(registry, metricsRecordBuilder);
  }
}
 
Example 6
Source File: MetricsStochasticBalancerSourceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName);

  if (stochasticCosts != null) {
    synchronized (stochasticCosts) {
      for (Map.Entry<String, Map<String, Double>> tableEntry : stochasticCosts.entrySet()) {
        for (Map.Entry<String, Double> costEntry : tableEntry.getValue().entrySet()) {
          String attrName = tableEntry.getKey() + TABLE_FUNCTION_SEP + costEntry.getKey();
          Double cost = costEntry.getValue();
          String functionDesc = costFunctionDescs.get(costEntry.getKey());

          if (functionDesc == null) {
            functionDesc = costEntry.getKey();
          }

          metricsRecordBuilder.addGauge(Interns.info(attrName, functionDesc), cost);
        }
      }
    }
  }
  metricsRegistry.snapshot(metricsRecordBuilder, all);
}
 
Example 7
Source File: MetricsTableLatenciesImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);
  // source is registered in supers constructor, sometimes called before the whole initialization.
  metricsRegistry.snapshot(mrb, all);
  if (metricsAdapter != null) {
    // snapshot MetricRegistry as well
    metricsAdapter.snapshotAllMetrics(registry, mrb);
  }
}
 
Example 8
Source File: MetricsRegionAggregateSourceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Yes this is a get function that doesn't return anything.  Thanks Hadoop for breaking all
 * expectations of java programmers.  Instead of returning anything Hadoop metrics expects
 * getMetrics to push the metrics into the collector.
 *
 * @param collector the collector
 * @param all       get all the metrics regardless of when they last changed.
 */
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  MetricsRecordBuilder mrb = collector.addRecord(metricsName);

  if (regionSources != null) {
    for (MetricsRegionSource regionMetricSource : regionSources) {
      if (regionMetricSource instanceof MetricsRegionSourceImpl) {
        ((MetricsRegionSourceImpl) regionMetricSource).snapshot(mrb, all);
      }
    }
    mrb.addGauge(Interns.info(NUM_REGIONS, NUMBER_OF_REGIONS_DESC), regionSources.size());
    metricsRegistry.snapshot(mrb, all);
  }
}
 
Example 9
Source File: MetricsTableAggregateSourceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Yes this is a get function that doesn't return anything.  Thanks Hadoop for breaking all
 * expectations of java programmers.  Instead of returning anything Hadoop metrics expects
 * getMetrics to push the metrics into the collector.
 *
 * @param collector the collector
 * @param all       get all the metrics regardless of when they last changed.
 */
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  MetricsRecordBuilder mrb = collector.addRecord(metricsName);
  if (tableSources != null) {
    for (MetricsTableSource tableMetricSource : tableSources.values()) {
      if (tableMetricSource instanceof MetricsTableSourceImpl) {
        ((MetricsTableSourceImpl) tableMetricSource).snapshot(mrb, all);
      }
    }
    mrb.addGauge(Interns.info(NUM_TABLES, NUMBER_OF_TABLES_DESC), tableSources.size());
    metricsRegistry.snapshot(mrb, all);
  }
}
 
Example 10
Source File: MetricsAssignmentManagerSourceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName);
  metricsRegistry.snapshot(metricsRecordBuilder, all);
  if(metricsAdapter != null) {
    metricsAdapter.snapshotAllMetrics(registry, metricsRecordBuilder);
  }
}
 
Example 11
Source File: MetricsUserAggregateSourceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  MetricsRecordBuilder mrb = collector.addRecord(metricsName);

  if (userSources != null) {
    for (MetricsUserSource userMetricSource : userSources.values()) {
      if (userMetricSource instanceof MetricsUserSourceImpl) {
        ((MetricsUserSourceImpl) userMetricSource).snapshot(mrb, all);
      }
    }
    mrb.addGauge(Interns.info(NUM_USERS, NUMBER_OF_USERS_DESC), userSources.size());
    metricsRegistry.snapshot(mrb, all);
  }
}
 
Example 12
Source File: HBaseMetrics2HadoopMetricsAdapter.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 13
Source File: HadoopMetrics2Reporter.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
    MetricsRecordBuilder builder = collector.addRecord(recordName);
    if (null != context) {
        builder.setContext(context);
    }

    // Synchronizing here ensures that the dropwizard metrics collection side is excluded from executing
    // at the same time we are pulling elements from the queues.
    synchronized (this) {
        snapshotAllMetrics(builder);
    }

    metrics2Registry.snapshot(builder, all);
}
 
Example 14
Source File: GlobalMetricRegistriesAdapter.java    From phoenix with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 15
Source File: HadoopMetrics2Reporter.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
    MetricsRecordBuilder builder = collector.addRecord(recordName);
    if (null != context) {
        builder.setContext(context);
    }

    // Synchronizing here ensures that the dropwizard metrics collection side is excluded from executing
    // at the same time we are pulling elements from the queues.
    synchronized (this) {
        snapshotAllMetrics(builder);
    }

    metrics2Registry.snapshot(builder, all);
}
 
Example 16
Source File: MetricsUserSourceImpl.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder mrb = metricsCollector.addRecord(this.userNamePrefix);
  registry.snapshot(mrb, all);
}
 
Example 17
Source File: MetricsHBaseServerSourceImpl.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);

  if (wrapper != null) {
    mrb.addGauge(Interns.info(QUEUE_SIZE_NAME, QUEUE_SIZE_DESC), wrapper.getTotalQueueSize())
        .addGauge(Interns.info(GENERAL_QUEUE_NAME, GENERAL_QUEUE_DESC),
            wrapper.getGeneralQueueLength())
        .addGauge(Interns.info(REPLICATION_QUEUE_NAME,
            REPLICATION_QUEUE_DESC), wrapper.getReplicationQueueLength())
        .addGauge(Interns.info(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_DESC),
            wrapper.getPriorityQueueLength())
        .addGauge(Interns.info(METAPRIORITY_QUEUE_NAME, METAPRIORITY_QUEUE_DESC),
            wrapper.getMetaPriorityQueueLength())
        .addGauge(Interns.info(NUM_OPEN_CONNECTIONS_NAME,
            NUM_OPEN_CONNECTIONS_DESC), wrapper.getNumOpenConnections())
        .addGauge(Interns.info(NUM_ACTIVE_HANDLER_NAME,
            NUM_ACTIVE_HANDLER_DESC), wrapper.getActiveRpcHandlerCount())
        .addGauge(Interns.info(NUM_ACTIVE_GENERAL_HANDLER_NAME, NUM_ACTIVE_GENERAL_HANDLER_DESC),
          wrapper.getActiveGeneralRpcHandlerCount())
        .addGauge(
          Interns.info(NUM_ACTIVE_PRIORITY_HANDLER_NAME, NUM_ACTIVE_PRIORITY_HANDLER_DESC),
          wrapper.getActivePriorityRpcHandlerCount())
        .addGauge(
          Interns.info(NUM_ACTIVE_REPLICATION_HANDLER_NAME, NUM_ACTIVE_REPLICATION_HANDLER_DESC),
          wrapper.getActiveReplicationRpcHandlerCount())
        .addCounter(Interns.info(NUM_GENERAL_CALLS_DROPPED_NAME,
            NUM_GENERAL_CALLS_DROPPED_DESC), wrapper.getNumGeneralCallsDropped())
        .addCounter(Interns.info(NUM_LIFO_MODE_SWITCHES_NAME,
            NUM_LIFO_MODE_SWITCHES_DESC), wrapper.getNumLifoModeSwitches())
        .addGauge(Interns.info(WRITE_QUEUE_NAME, WRITE_QUEUE_DESC),
            wrapper.getWriteQueueLength())
        .addGauge(Interns.info(READ_QUEUE_NAME, READ_QUEUE_DESC),
            wrapper.getReadQueueLength())
        .addGauge(Interns.info(SCAN_QUEUE_NAME, SCAN_QUEUE_DESC),
            wrapper.getScanQueueLength())
        .addGauge(Interns.info(NUM_ACTIVE_WRITE_HANDLER_NAME, NUM_ACTIVE_WRITE_HANDLER_DESC),
          wrapper.getActiveWriteRpcHandlerCount())
        .addGauge(Interns.info(NUM_ACTIVE_READ_HANDLER_NAME, NUM_ACTIVE_READ_HANDLER_DESC),
          wrapper.getActiveReadRpcHandlerCount())
        .addGauge(Interns.info(NUM_ACTIVE_SCAN_HANDLER_NAME, NUM_ACTIVE_SCAN_HANDLER_DESC),
          wrapper.getActiveScanRpcHandlerCount())
        .addGauge(Interns.info(NETTY_DM_USAGE_NAME, NETTY_DM_USAGE_DESC),
          wrapper.getNettyDmUsage());
  }

  metricsRegistry.snapshot(mrb, all);
}
 
Example 18
Source File: MetricsMasterSourceImpl.java    From hbase with Apache License 2.0 4 votes vote down vote up
@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(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()));
  }

  metricsRegistry.snapshot(metricsRecordBuilder, all);
  if(metricsAdapter != null) {
    metricsAdapter.snapshotAllMetrics(registry, metricsRecordBuilder);
  }
}
 
Example 19
Source File: TestMetricsAnnotations.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  collector.addRecord("foo");
}
 
Example 20
Source File: RocksDBStoreMBean.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean b) {
  MetricsRecordBuilder rb = metricsCollector.addRecord(contextName);
  getHistogramData(rb);
  getTickerTypeData(rb);
}