当前位置: 首页>>代码示例>>Java>>正文


Java DatanodeDescriptor.getDfsUsedPercent方法代码示例

本文整理汇总了Java中org.apache.hadoop.hdfs.server.namenode.DatanodeDescriptor.getDfsUsedPercent方法的典型用法代码示例。如果您正苦于以下问题:Java DatanodeDescriptor.getDfsUsedPercent方法的具体用法?Java DatanodeDescriptor.getDfsUsedPercent怎么用?Java DatanodeDescriptor.getDfsUsedPercent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hdfs.server.namenode.DatanodeDescriptor的用法示例。


在下文中一共展示了DatanodeDescriptor.getDfsUsedPercent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doUpdates

import org.apache.hadoop.hdfs.server.namenode.DatanodeDescriptor; //导入方法依赖的package包/类
/**
 * Since this object is a registered updater, this method will be called
 * periodically, e.g. every 5 seconds.
 * We set the metrics value within  this function before pushing it out. 
 * FSNamesystem updates its own local variables which are
 * light weight compared to Metrics counters. 
 *
 * Some of the metrics are explicity casted to int. Few metrics collectors
 * do not handle long values. It is safe to cast to int for now as all these
 * values fit in int value.
 * Metrics related to DFS capacity are stored in bytes which do not fit in 
 * int, so they are rounded to GB
 */
public void doUpdates(MetricsContext unused) {
  /** 
   * ToFix
   * If the metrics counter were instead stored in the metrics objects themselves
   * we could avoid copying the values on each update.
   */
  ArrayList<DatanodeDescriptor> live = new ArrayList<DatanodeDescriptor>(); 
  populateDatanodeMetrics(live, new ArrayList<DatanodeDescriptor>());
  
  float datanodeMin = 0;
  float datanodeMedian = 0;
  float datanodeMax = 0;
  float datanodeStdev = 0;
  
  if (live.size() > 0) {
    float totalDFSUsed = 0;
    float[] usages = new float[live.size()];
    int i = 0;
    for (DatanodeDescriptor dn : live) {
      usages[i++] = dn.getDfsUsedPercent();
      totalDFSUsed += dn.getDfsUsedPercent();
    }
    totalDFSUsed /= live.size();
    Arrays.sort(usages);
    datanodeMedian = usages[usages.length/2];
    datanodeMax = usages[usages.length - 1];
    datanodeMin = usages[0];
    
    for (i = 0; i < usages.length; i++) {
      datanodeStdev += (usages[i] - totalDFSUsed) * (usages[i] - totalDFSUsed);
    }
    datanodeStdev = (float) Math.sqrt(datanodeStdev/live.size());
  }
  
  synchronized (this) {
    numDeadMonitoringThread.set(fsNameSystem.getNumDeadMonitoringThread());
    filesTotal.set((int) fsNameSystem.getFilesAndDirectoriesTotal());
    blocksTotal.set((int)fsNameSystem.getBlocksTotal());
    diskSpaceTotalGB.set(roundBytesToGBytes(fsNameSystem.getDiskSpaceTotal()));
    datanodesUsagePctMin.set((int) datanodeMin);
    datanodesUsagePctMax.set((int) datanodeMax);
    datanodesUsagePctMedian.set((int) datanodeMedian);
    datanodesUsagePctStdev.set((int) datanodeStdev);
    capacityTotalGB.set(roundBytesToGBytes(fsNameSystem.getCapacityTotal()));
    capacityUsedGB.set(roundBytesToGBytes(fsNameSystem.getCapacityUsed()));
    capacityRemainingGB.set(roundBytesToGBytes(fsNameSystem.
                                             getCapacityRemaining()));
    totalLoad.set(fsNameSystem.getTotalLoad());
    corruptBlocks.set((int)fsNameSystem.getCorruptReplicaBlocks());
    excessBlocks.set((int)fsNameSystem.getExcessBlocks());
    pendingDeletionBlocks.set((int)fsNameSystem.getPendingDeletionBlocks());
    pendingReplicationBlocks.set((int)fsNameSystem.
                                 getPendingReplicationBlocks());
    underReplicatedBlocks.set((int)fsNameSystem.getUnderReplicatedBlocks());
    scheduledReplicationBlocks.set((int)fsNameSystem.
                                    getScheduledReplicationBlocks());
    missingBlocks.set((int)fsNameSystem.getMissingBlocksCount());
    blockCapacity.set(fsNameSystem.getBlockCapacity());
    numLeases.set(fsNameSystem.leaseManager.countLease());
    numUnderConstructionFiles.set(fsNameSystem.leaseManager.countPath());
    upgradeTime.set(fsNameSystem.getUpgradeTime());
    
    for (MetricsBase m : registry.getMetricsList()) {
      m.pushMetric(metricsRecord);
    }
  }
  metricsRecord.update();
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:82,代码来源:FSNamesystemMetrics.java


注:本文中的org.apache.hadoop.hdfs.server.namenode.DatanodeDescriptor.getDfsUsedPercent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。