001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.hbtop.mode; 019 020import java.util.ArrayList; 021import java.util.Arrays; 022import java.util.Collections; 023import java.util.List; 024import java.util.Map; 025import java.util.stream.Collectors; 026 027import org.apache.hadoop.hbase.ClusterMetrics; 028import org.apache.hadoop.hbase.ServerMetrics; 029import org.apache.hadoop.hbase.hbtop.Record; 030import org.apache.hadoop.hbase.hbtop.RecordFilter; 031import org.apache.hadoop.hbase.hbtop.field.Field; 032import org.apache.hadoop.hbase.hbtop.field.FieldInfo; 033import org.apache.yetus.audience.InterfaceAudience; 034 035 036/** 037 * Implementation for {@link ModeStrategy} for RegionServer Mode. 038 */ 039@InterfaceAudience.Private 040public final class RegionServerModeStrategy implements ModeStrategy { 041 042 private final List<FieldInfo> fieldInfos = Arrays.asList( 043 new FieldInfo(Field.REGION_SERVER, 0, true), 044 new FieldInfo(Field.LONG_REGION_SERVER, 0, false), 045 new FieldInfo(Field.REGION_COUNT, 7, true), 046 new FieldInfo(Field.REQUEST_COUNT_PER_SECOND, 10, true), 047 new FieldInfo(Field.READ_REQUEST_COUNT_PER_SECOND, 10, true), 048 new FieldInfo(Field.FILTERED_READ_REQUEST_COUNT_PER_SECOND, 8, true), 049 new FieldInfo(Field.WRITE_REQUEST_COUNT_PER_SECOND, 10, true), 050 new FieldInfo(Field.STORE_FILE_SIZE, 13, true), 051 new FieldInfo(Field.UNCOMPRESSED_STORE_FILE_SIZE, 15, false), 052 new FieldInfo(Field.NUM_STORE_FILES, 7, true), 053 new FieldInfo(Field.MEM_STORE_SIZE, 11, true), 054 new FieldInfo(Field.USED_HEAP_SIZE, 11, true), 055 new FieldInfo(Field.MAX_HEAP_SIZE, 11, true) 056 ); 057 058 private final RegionModeStrategy regionModeStrategy = new RegionModeStrategy(); 059 060 RegionServerModeStrategy(){ 061 } 062 063 @Override 064 public List<FieldInfo> getFieldInfos() { 065 return fieldInfos; 066 } 067 068 @Override 069 public Field getDefaultSortField() { 070 return Field.REQUEST_COUNT_PER_SECOND; 071 } 072 073 @Override public List<Record> getRecords(ClusterMetrics clusterMetrics, 074 List<RecordFilter> pushDownFilters) { 075 // Get records from RegionModeStrategy and add REGION_COUNT field 076 List<Record> records = regionModeStrategy.selectModeFieldsAndAddCountField(fieldInfos, 077 regionModeStrategy.getRecords(clusterMetrics, pushDownFilters), Field.REGION_COUNT); 078 // Aggregation by LONG_REGION_SERVER field 079 Map<String, Record> retMap = 080 ModeStrategyUtils.aggregateRecords(records, Field.LONG_REGION_SERVER).stream() 081 .collect(Collectors.toMap(r -> r.get(Field.LONG_REGION_SERVER).asString(), r -> r)); 082 083 // Add USED_HEAP_SIZE field and MAX_HEAP_SIZE field 084 for (ServerMetrics sm : clusterMetrics.getLiveServerMetrics().values()) { 085 Record record = retMap.get(sm.getServerName().getServerName()); 086 if (record == null) { 087 continue; 088 } 089 090 Record newRecord = Record.builder().putAll(record) 091 .put(Field.USED_HEAP_SIZE, sm.getUsedHeapSize()) 092 .put(Field.MAX_HEAP_SIZE, sm.getMaxHeapSize()).build(); 093 094 retMap.put(sm.getServerName().getServerName(), newRecord); 095 } 096 097 return new ArrayList<>(retMap.values()); 098 } 099 100 @Override 101 public DrillDownInfo drillDown(Record selectedRecord) { 102 List<RecordFilter> initialFilters = Collections.singletonList(RecordFilter 103 .newBuilder(Field.REGION_SERVER) 104 .doubleEquals(selectedRecord.get(Field.REGION_SERVER))); 105 return new DrillDownInfo(Mode.REGION, initialFilters); 106 } 107}