Exemple #1
0
 public Map<String, Long> getRegionSizes(String tableName) {
   Map<String, Long> regions = new HashMap<>();
   try {
     final Table table = connection.getTable(TableName.valueOf(tableName));
     RegionLocator regionLocator = connection.getRegionLocator(table.getName());
     List<HRegionLocation> tableRegionInfos = regionLocator.getAllRegionLocations();
     Set<byte[]> tableRegions = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
     for (HRegionLocation regionInfo : tableRegionInfos) {
       tableRegions.add(regionInfo.getRegionInfo().getRegionName());
     }
     ClusterStatus clusterStatus = connection.getAdmin().getClusterStatus();
     Collection<ServerName> servers = clusterStatus.getServers();
     final long megaByte = 1024L * 1024L;
     for (ServerName serverName : servers) {
       ServerLoad serverLoad = clusterStatus.getLoad(serverName);
       for (RegionLoad regionLoad : serverLoad.getRegionsLoad().values()) {
         byte[] regionId = regionLoad.getName();
         if (tableRegions.contains(regionId)) {
           long regionSizeBytes = regionLoad.getStorefileSizeMB() * megaByte;
           regions.put(regionLoad.getNameAsString(), regionSizeBytes);
         }
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
   return regions;
 }
 @Override
 public void write(DataOutput out) throws IOException {
   out.writeInt(status.size());
   for (ClusterStatus cs : status) {
     cs.write(out);
   }
 }
 /** {@inheritDoc} */
 @Override
 public int getBackupMastersSize() {
   int size = 0;
   for (ClusterStatus cs : status) {
     size += cs.getBackupMastersSize();
   }
   return size;
 }
 /** {@inheritDoc} */
 @Override
 public int hashCode() {
   int hashCode = VERSION;
   for (ClusterStatus cs : status) {
     hashCode += cs.hashCode();
   }
   return hashCode;
 }
 /** {@inheritDoc} */
 @Override
 public int getDeadServers() {
   int count = 0;
   for (ClusterStatus cs : status) {
     count += cs.getDeadServers();
   }
   return count;
 }
 /** {@inheritDoc} */
 @Override
 public int getRegionsCount() {
   int count = 0;
   for (ClusterStatus cs : status) {
     count += cs.getRegionsCount();
   }
   return count;
 }
 /** {@inheritDoc} */
 @Override
 public Map<String, RegionState> getRegionsInTransition() {
   Map<String, RegionState> state = new HashMap<String, RegionState>();
   for (ClusterStatus cs : status) {
     if (cs.getRegionsInTransition() != null) {
       state.putAll(cs.getRegionsInTransition());
     }
   }
   return state;
 }
 @Override
 public void readFields(DataInput in) throws IOException {
   int size = in.readInt();
   status = new ArrayList<ClusterStatus>(size);
   for (int i = 0; i < size; i++) {
     ClusterStatus cs = new ClusterStatus();
     cs.readFields(in);
     status.add(cs);
   }
 }
  public void renderNoFlush(
      @SuppressWarnings({"unused", "hiding"}) final java.io.Writer jamonWriter)
      throws java.io.IOException {
    // 35, 1

    Collection<ServerName> backupMasters = null;
    if (master.isActiveMaster()) {
      ClusterStatus status = master.getClusterStatus();
      backupMasters = status.getBackupMasters();
    }

    // 43, 1
    jamonWriter.write("<table class=\"table table-striped\">\n");
    // 44, 1
    if ((backupMasters != null && backupMasters.size() > 0)) {
      // 44, 59
      jamonWriter.write(
          "\n<tr>\n    <th>ServerName</th>\n    <th>Port</th>\n    <th>Start Time</th>\n</tr>\n");
      // 50, 1

      ServerName[] serverNames = backupMasters.toArray(new ServerName[backupMasters.size()]);
      Arrays.sort(serverNames);
      for (ServerName serverName : serverNames) {

        // 55, 1
        jamonWriter.write("<tr>\n    <td>");
        // 56, 9
        org.jamon.escaping.Escaping.HTML.write(
            org.jamon.emit.StandardEmitter.valueOf(serverName.getHostname()), jamonWriter);
        // 56, 39
        jamonWriter.write("</td>\n    <td>");
        // 57, 9
        org.jamon.escaping.Escaping.HTML.write(
            org.jamon.emit.StandardEmitter.valueOf(serverName.getPort()), jamonWriter);
        // 57, 35
        jamonWriter.write("</td>\n    <td>");
        // 58, 9
        org.jamon.escaping.Escaping.HTML.write(
            org.jamon.emit.StandardEmitter.valueOf(new Date(serverName.getStartcode())),
            jamonWriter);
        // 58, 50
        jamonWriter.write("</td>\n</tr>\n");
        // 60, 1

      }
    }
    // 63, 7
    jamonWriter.write("\n<tr><td>Total:");
    // 64, 15
    org.jamon.escaping.Escaping.HTML.write(
        org.jamon.emit.StandardEmitter.valueOf((backupMasters != null) ? backupMasters.size() : 0),
        jamonWriter);
    // 64, 71
    jamonWriter.write("</td>\n</table>\n\n\n\n\n");
  }
 /** {@inheritDoc} */
 @Override
 public ServerLoad getLoad(ServerName sn) {
   ServerLoad load = null;
   for (ClusterStatus cs : status) {
     load = cs.getLoad(sn);
     if (load != null) {
       break;
     }
   }
   return load;
 }
 /** {@inheritDoc} */
 @Override
 public Collection<ServerName> getDeadServerNames() {
   List<ServerName> deadServerNames = new ArrayList<ServerName>();
   for (ClusterStatus cs : status) {
     if (cs.getDeadServerNames() != null) {
       for (ServerName sn : cs.getDeadServerNames()) {
         deadServerNames.add(sn);
       }
     }
   }
   return deadServerNames;
 }
 /** @deprecated Use {@link #getServers()} */
 @Override
 public Collection<ServerName> getServerInfo() {
   List<ServerName> serverInfos = new ArrayList<ServerName>();
   for (ClusterStatus cs : status) {
     if (cs.getServerInfo() != null) {
       for (ServerName sn : cs.getServerInfo()) {
         serverInfos.add(sn);
       }
     }
   }
   return serverInfos;
 }
 /** {@inheritDoc} */
 @Override
 public String[] getMasterCoprocessors() {
   List<String> masterCoprocessors = new ArrayList<String>();
   for (ClusterStatus cs : status) {
     if (cs.getMasterCoprocessors() != null) {
       for (String mcr : cs.getMasterCoprocessors()) {
         masterCoprocessors.add(mcr);
       }
     }
   }
   return masterCoprocessors.toArray(new String[0]);
 }
 /**
  * Gets the cluster id. This id is composed of the ids of all the sub cluster, looks like
  * id1,id2,id3...
  */
 @Override
 public String getClusterId() {
   StringBuilder sr = new StringBuilder();
   for (ClusterStatus cs : status) {
     sr.append(cs.getClusterId()).append(",");
   }
   if (sr.length() > 1) {
     return sr.substring(0, sr.length() - 1);
   } else {
     return sr.toString();
   }
 }
 /** {@inheritDoc} */
 @Override
 public Collection<ServerName> getBackupMasters() {
   List<ServerName> backMasters = new ArrayList<ServerName>();
   for (ClusterStatus cs : status) {
     if (cs.getBackupMasters() != null) {
       for (ServerName sn : cs.getBackupMasters()) {
         backMasters.add(sn);
       }
     }
   }
   return backMasters;
 }
 /** {@inheritDoc} */
 @Override
 public String getHBaseVersion() {
   Set<String> versions = new TreeSet<String>();
   for (ClusterStatus cs : status) {
     versions.add(cs.getHBaseVersion());
   }
   StringBuilder sr = new StringBuilder();
   for (String version : versions) {
     sr.append(version).append(",");
   }
   if (sr.length() > 1) {
     return sr.substring(0, sr.length() - 1);
   } else {
     return sr.toString();
   }
 }
  public static Map<String, HRegionContent> getRegionMap(HTable table, HBaseAdmin admin)
      throws Exception {
    // TODO Auto-generated method stub
    Map<String, HRegionContent> regionMap = new HashMap<String, HRegionContent>();

    try {
      Map<HRegionInfo, ServerName> regionsInfo = table.getRegionLocations();
      for (HRegionInfo ri : regionsInfo.keySet()) {
        HRegionContent regionContent = new HRegionContent();
        regionContent.tableName = ri.getTableNameAsString();
        regionContent.encodedName = ri.getEncodedName();
        regionContent.regionName = ri.getRegionNameAsString();
        regionContent.regionNameBytes = ri.getRegionName();
        regionContent.regionId = ri.getRegionId();
        regionContent.startKey = ri.getStartKey();
        regionContent.endKey = ri.getEndKey();

        regionMap.put(regionContent.encodedName, regionContent);
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    ClusterStatus status = admin.getClusterStatus();
    /*      System.out.println("Cluster Status:\n--------------");
    System.out.println("HBase Version: " + status.getHBaseVersion());
    System.out.println("Version: " + status.getVersion());
    System.out.println("No. Live Servers: " + status.getServersSize());
    System.out.println("Cluster ID: " + status.getClusterId());
    System.out.println("Servers: " + status.getServers());
    System.out.println("No. Dead Servers: " + status.getDeadServers());
    System.out.println("Dead Servers: " + status.getDeadServerNames());

    System.out.println("No. Regions: " + status.getRegionsCount());
    System.out.println("Regions in Transition: " + status.getRegionsInTransition());
    System.out.println("No. Requests: " + status.getRequestsCount());
    System.out.println("Avg Load: " + status.getAverageLoad());
    System.out.println("\nServer Info:\n--------------");*/
    for (ServerName server : status.getServers()) {
      /*System.out.println("Hostname: " + server.getHostname());
      System.out.println("Host and Port: " + server.getHostAndPort());
      System.out.println("Server Name: " + server.getServerName());
      System.out.println("RPC Port: " + server.getPort());
      System.out.println("Start Code: " + server.getStartcode());*/
      HServerLoad load = status.getLoad(server);
      /*System.out.println("\nServer Load:\n--------------");
      System.out.println("Load: " + load.getLoad());
      System.out.println("Max Heap (MB): " + load.getMaxHeapMB());
      System.out.println("Memstore Size (MB): " + load.getMemStoreSizeInMB());
      System.out.println("No. Regions: " + load.getNumberOfRegions());
      System.out.println("No. Requests: " + load.getNumberOfRequests());
      System.out.println("Storefile Index Size (MB): " +
      load.getStorefileIndexSizeInMB());
      System.out.println("No. Storefiles: " + load.getStorefiles());
      System.out.println("Storefile Size (MB): " + load.getStorefileSizeInMB());
      System.out.println("Used Heap (MB): " + load.getUsedHeapMB());
      System.out.println("\nRegion Load:\n--------------");*/
      for (Map.Entry<byte[], HServerLoad.RegionLoad> entry : load.getRegionsLoad().entrySet()) {

        HServerLoad.RegionLoad regionLoad = entry.getValue();
        String regionLoadName = regionLoad.getNameAsString();
        String[] tmpStrings = regionLoadName.split("\\.");
        String encodeName = tmpStrings[tmpStrings.length - 1];

        if (!regionMap.containsKey(encodeName)) {
          continue;
        }

        HRegionContent regionContent = regionMap.get(encodeName);
        regionContent.stores = regionLoad.getStores();
        regionContent.storeFiles = regionLoad.getStorefiles();
        regionContent.storefileSizeMB = regionLoad.getStorefileSizeMB();
        regionContent.storefileIndexSizeMB = regionLoad.getStorefileIndexSizeMB();
        regionContent.memStoreSizeMB = regionLoad.getMemStoreSizeMB();
        regionContent.requestsCount = regionLoad.getRequestsCount();
        regionContent.readRequestCount = regionLoad.getReadRequestsCount();
        regionContent.writeRequestCount = regionLoad.getWriteRequestsCount();
      }
    }

    int count = 0;
    for (HRegionContent regionContent : regionMap.values()) {

      /*System.out.println("table name : " + regionContent.tableName);
      System.out.println("encoded name : " + regionContent.encodedName);
      System.out.println("region name : " + regionContent.regionName);
      System.out.println("regionId : " + regionContent.regionId);
      System.out.println("startKey : " + regionContent.startKey.toString());
      System.out.println("endKey : " + regionContent.endKey.toString());

      System.out.println("No. Stores: " + regionContent.stores);
      System.out.println("No. Storefiles: " + regionContent.storeFiles);
      System.out.println("Storefile Size (MB): " + regionContent.storefileSizeMB);
      System.out.println("Storefile Index Size (MB): " + regionContent.storefileIndexSizeMB);
      System.out.println("Memstore Size (MB): " + regionContent.memStoreSizeMB);
      System.out.println("No. Requests: " + regionContent.requestsCount);
      System.out.println("No. Read Requests: " +
      		regionContent.readRequestCount);
      System.out.println("No. Write Requests: " +
      		regionContent.writeRequestCount);
      System.out.println();*/
      count++;
    }

    /*LOG.info("region sum num: " + regionMap.size());
    LOG.info("not null region num:" + count);
    LOG.info("file size :" + fileSize);*/

    return regionMap;
  }
Exemple #18
0
  public void printStats() throws IOException {
    Admin admin = connection.getAdmin();

    ClusterStatus status =
        admin.getClusterStatus(); // co ClusterStatusExample-1-GetStatus Get the cluster status.
    System.out.println("Cluster Status:\n--------------");
    System.out.println("HBase Version: " + status.getHBaseVersion());
    System.out.println("Version: " + status.getVersion());
    System.out.println("Cluster ID: " + status.getClusterId());
    System.out.println("Master: " + status.getMaster());
    System.out.println("No. Backup Masters: " + status.getBackupMastersSize());
    System.out.println("Backup Masters: " + status.getBackupMasters());
    System.out.println("No. Live Servers: " + status.getServersSize());
    System.out.println("Servers: " + status.getServers());
    System.out.println("No. Dead Servers: " + status.getDeadServers());
    System.out.println("Dead Servers: " + status.getDeadServerNames());
    System.out.println("No. Regions: " + status.getRegionsCount());
    System.out.println("Regions in Transition: " + status.getRegionsInTransition());
    System.out.println("No. Requests: " + status.getRequestsCount());
    System.out.println("Avg Load: " + status.getAverageLoad());
    System.out.println("Balancer On: " + status.getBalancerOn());
    System.out.println("Is Balancer On: " + status.isBalancerOn());
    System.out.println("Master Coprocessors: " + Arrays.asList(status.getMasterCoprocessors()));
    System.out.println("\nServer Info:\n--------------");
    for (ServerName server :
        status
            .getServers()) { // co ClusterStatusExample-2-ServerInfo Iterate over the included
                             // server instances.
      System.out.println("Hostname: " + server.getHostname());
      System.out.println("Host and Port: " + server.getHostAndPort());
      System.out.println("Server Name: " + server.getServerName());
      System.out.println("RPC Port: " + server.getPort());
      System.out.println("Start Code: " + server.getStartcode());
      ServerLoad load =
          status.getLoad(
              server); // co ClusterStatusExample-3-ServerLoad Retrieve the load details for the
                       // current server.
      System.out.println("\nServer Load:\n--------------");
      System.out.println("Info Port: " + load.getInfoServerPort());
      System.out.println("Load: " + load.getLoad());
      System.out.println("Max Heap (MB): " + load.getMaxHeapMB());
      System.out.println("Used Heap (MB): " + load.getUsedHeapMB());
      System.out.println("Memstore Size (MB): " + load.getMemstoreSizeInMB());
      System.out.println("No. Regions: " + load.getNumberOfRegions());
      System.out.println("No. Requests: " + load.getNumberOfRequests());
      System.out.println("Total No. Requests: " + load.getTotalNumberOfRequests());
      System.out.println("No. Requests per Sec: " + load.getRequestsPerSecond());
      System.out.println("No. Read Requests: " + load.getReadRequestsCount());
      System.out.println("No. Write Requests: " + load.getWriteRequestsCount());
      System.out.println("No. Stores: " + load.getStores());
      System.out.println("Store Size Uncompressed (MB): " + load.getStoreUncompressedSizeMB());
      System.out.println("No. Storefiles: " + load.getStorefiles());
      System.out.println("Storefile Size (MB): " + load.getStorefileSizeInMB());
      System.out.println("Storefile Index Size (MB): " + load.getStorefileIndexSizeInMB());
      System.out.println("Root Index Size: " + load.getRootIndexSizeKB());
      System.out.println("Total Bloom Size: " + load.getTotalStaticBloomSizeKB());
      System.out.println("Total Index Size: " + load.getTotalStaticIndexSizeKB());
      System.out.println("Current Compacted Cells: " + load.getCurrentCompactedKVs());
      System.out.println("Total Compacting Cells: " + load.getTotalCompactingKVs());
      System.out.println("Coprocessors1: " + Arrays.asList(load.getRegionServerCoprocessors()));
      System.out.println("Coprocessors2: " + Arrays.asList(load.getRsCoprocessors()));
      System.out.println("Replication Load Sink: " + load.getReplicationLoadSink());
      System.out.println("Replication Load Source: " + load.getReplicationLoadSourceList());
      System.out.println("\nRegion Load:\n--------------");
      for (Map.Entry<byte[], RegionLoad>
          entry : // co ClusterStatusExample-4-Regions Iterate over the region details of the
                  // current server.
          load.getRegionsLoad().entrySet()) {
        System.out.println("Region: " + Bytes.toStringBinary(entry.getKey()));
        RegionLoad regionLoad =
            entry
                .getValue(); // co ClusterStatusExample-5-RegionLoad Get the load details for the
                             // current region.
        System.out.println("Name: " + Bytes.toStringBinary(regionLoad.getName()));
        System.out.println("Name (as String): " + regionLoad.getNameAsString());
        System.out.println("No. Requests: " + regionLoad.getRequestsCount());
        System.out.println("No. Read Requests: " + regionLoad.getReadRequestsCount());
        System.out.println("No. Write Requests: " + regionLoad.getWriteRequestsCount());
        System.out.println("No. Stores: " + regionLoad.getStores());
        System.out.println("No. Storefiles: " + regionLoad.getStorefiles());
        System.out.println("Data Locality: " + regionLoad.getDataLocality());
        System.out.println("Storefile Size (MB): " + regionLoad.getStorefileSizeMB());
        System.out.println("Storefile Index Size (MB): " + regionLoad.getStorefileIndexSizeMB());
        System.out.println("Memstore Size (MB): " + regionLoad.getMemStoreSizeMB());
        System.out.println("Root Index Size: " + regionLoad.getRootIndexSizeKB());
        System.out.println("Total Bloom Size: " + regionLoad.getTotalStaticBloomSizeKB());
        System.out.println("Total Index Size: " + regionLoad.getTotalStaticIndexSizeKB());
        System.out.println("Current Compacted Cells: " + regionLoad.getCurrentCompactedKVs());
        System.out.println("Total Compacting Cells: " + regionLoad.getTotalCompactingKVs());
        System.out.println();
      }
    }
  }