Search in sources :

Example 6 with Record

use of org.apache.hadoop.hbase.hbtop.Record in project hbase by apache.

the class RegionServerModeStrategy method getRecords.

@Override
public List<Record> getRecords(ClusterMetrics clusterMetrics, List<RecordFilter> pushDownFilters) {
    // Get records from RegionModeStrategy and add REGION_COUNT field
    List<Record> records = regionModeStrategy.selectModeFieldsAndAddCountField(fieldInfos, regionModeStrategy.getRecords(clusterMetrics, pushDownFilters), Field.REGION_COUNT);
    // Aggregation by LONG_REGION_SERVER field
    Map<String, Record> retMap = ModeStrategyUtils.aggregateRecords(records, Field.LONG_REGION_SERVER).stream().collect(Collectors.toMap(r -> r.get(Field.LONG_REGION_SERVER).asString(), r -> r));
    // Add USED_HEAP_SIZE field and MAX_HEAP_SIZE field
    for (ServerMetrics sm : clusterMetrics.getLiveServerMetrics().values()) {
        Record record = retMap.get(sm.getServerName().getServerName());
        if (record == null) {
            continue;
        }
        Record newRecord = Record.builder().putAll(record).put(Field.USED_HEAP_SIZE, sm.getUsedHeapSize()).put(Field.MAX_HEAP_SIZE, sm.getMaxHeapSize()).build();
        retMap.put(sm.getServerName().getServerName(), newRecord);
    }
    return new ArrayList<>(retMap.values());
}
Also used : RecordFilter(org.apache.hadoop.hbase.hbtop.RecordFilter) Arrays(java.util.Arrays) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Field(org.apache.hadoop.hbase.hbtop.field.Field) FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo) Map(java.util.Map) Record(org.apache.hadoop.hbase.hbtop.Record) Collections(java.util.Collections) ArrayList(java.util.ArrayList) Record(org.apache.hadoop.hbase.hbtop.Record) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics)

Example 7 with Record

use of org.apache.hadoop.hbase.hbtop.Record in project hbase by apache.

the class ClientModeStrategy method createRecords.

List<Record> createRecords(ClusterMetrics clusterMetrics) {
    List<Record> ret = new ArrayList<>();
    for (ServerMetrics serverMetrics : clusterMetrics.getLiveServerMetrics().values()) {
        long lastReportTimestamp = serverMetrics.getLastReportTimestamp();
        serverMetrics.getUserMetrics().values().forEach(um -> um.getClientMetrics().values().forEach(clientMetrics -> ret.add(createRecord(um.getNameAsString(), clientMetrics, lastReportTimestamp, serverMetrics.getServerName().getServerName()))));
    }
    return ret;
}
Also used : RecordFilter(org.apache.hadoop.hbase.hbtop.RecordFilter) Arrays(java.util.Arrays) UserMetrics(org.apache.hadoop.hbase.UserMetrics) Set(java.util.Set) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) HashMap(java.util.HashMap) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) Collectors(java.util.stream.Collectors) FieldValueType(org.apache.hadoop.hbase.hbtop.field.FieldValueType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Field(org.apache.hadoop.hbase.hbtop.field.Field) FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo) FieldValue(org.apache.hadoop.hbase.hbtop.field.FieldValue) Map(java.util.Map) Record(org.apache.hadoop.hbase.hbtop.Record) Collections(java.util.Collections) ArrayList(java.util.ArrayList) Record(org.apache.hadoop.hbase.hbtop.Record) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics)

Example 8 with Record

use of org.apache.hadoop.hbase.hbtop.Record in project hbase by apache.

the class ClientModeStrategy method aggregateRecordsAndAddDistinct.

/**
 * Aggregate the records and count the unique values for the given distinctField
 *
 * @param records               records to be processed
 * @param groupBy               Field on which group by needs to be done
 * @param distinctField         Field whose unique values needs to be counted
 * @param uniqueCountAssignedTo a target field to which the unique count is assigned to
 * @return aggregated records
 */
List<Record> aggregateRecordsAndAddDistinct(List<Record> records, Field groupBy, Field distinctField, Field uniqueCountAssignedTo) {
    List<Record> result = new ArrayList<>();
    records.stream().collect(Collectors.groupingBy(r -> r.get(groupBy))).values().forEach(val -> {
        Set<FieldValue> distinctValues = new HashSet<>();
        Map<Field, FieldValue> map = new HashMap<>();
        for (Record record : val) {
            for (Map.Entry<Field, FieldValue> field : record.entrySet()) {
                if (distinctField.equals(field.getKey())) {
                    // We will not be adding the field in the new record whose distinct count is required
                    distinctValues.add(record.get(distinctField));
                } else {
                    if (field.getKey().getFieldValueType() == FieldValueType.STRING) {
                        map.put(field.getKey(), field.getValue());
                    } else {
                        if (map.get(field.getKey()) == null) {
                            map.put(field.getKey(), field.getValue());
                        } else {
                            map.put(field.getKey(), map.get(field.getKey()).plus(field.getValue()));
                        }
                    }
                }
            }
        }
        // Add unique count field
        map.put(uniqueCountAssignedTo, uniqueCountAssignedTo.newValue(distinctValues.size()));
        result.add(Record.ofEntries(map.entrySet().stream().map(k -> Record.entry(k.getKey(), k.getValue()))));
    });
    return result;
}
Also used : RecordFilter(org.apache.hadoop.hbase.hbtop.RecordFilter) Arrays(java.util.Arrays) UserMetrics(org.apache.hadoop.hbase.UserMetrics) Set(java.util.Set) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) HashMap(java.util.HashMap) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) Collectors(java.util.stream.Collectors) FieldValueType(org.apache.hadoop.hbase.hbtop.field.FieldValueType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Field(org.apache.hadoop.hbase.hbtop.field.Field) FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo) FieldValue(org.apache.hadoop.hbase.hbtop.field.FieldValue) Map(java.util.Map) Record(org.apache.hadoop.hbase.hbtop.Record) Collections(java.util.Collections) Field(org.apache.hadoop.hbase.hbtop.field.Field) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Record(org.apache.hadoop.hbase.hbtop.Record) FieldValue(org.apache.hadoop.hbase.hbtop.field.FieldValue) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 9 with Record

use of org.apache.hadoop.hbase.hbtop.Record in project hbase by apache.

the class TopScreenView method showRecords.

private void showRecords(List<Header> headers, List<Record> records, Record selectedRecord) {
    TerminalPrinter printer = getTerminalPrinter(RECORD_START_ROW);
    int size;
    if (pageSize != null) {
        size = pageSize;
    } else {
        size = records.size();
    }
    List<String> buf = new ArrayList<>(headers.size());
    for (int i = 0; i < size; i++) {
        if (i < records.size()) {
            Record record = records.get(i);
            buf.clear();
            for (Header header : headers) {
                String value = "";
                if (record.containsKey(header.getField())) {
                    value = record.get(header.getField()).asString();
                }
                buf.add(limitLineLength(String.format(header.format(), value), header.getLength()));
            }
            String recordString = String.join(" ", buf);
            if (!recordString.isEmpty()) {
                recordString += " ";
            }
            if (record == selectedRecord) {
                printer.startHighlight().print(recordString).stopHighlight().endOfLine();
            } else {
                printer.print(recordString).endOfLine();
            }
        } else {
            printer.endOfLine();
        }
    }
}
Also used : TerminalPrinter(org.apache.hadoop.hbase.hbtop.terminal.TerminalPrinter) ArrayList(java.util.ArrayList) Record(org.apache.hadoop.hbase.hbtop.Record)

Aggregations

Record (org.apache.hadoop.hbase.hbtop.Record)9 ArrayList (java.util.ArrayList)5 FieldValue (org.apache.hadoop.hbase.hbtop.field.FieldValue)5 Collections (java.util.Collections)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ClusterMetrics (org.apache.hadoop.hbase.ClusterMetrics)4 RecordFilter (org.apache.hadoop.hbase.hbtop.RecordFilter)4 Field (org.apache.hadoop.hbase.hbtop.field.Field)4 FieldInfo (org.apache.hadoop.hbase.hbtop.field.FieldInfo)4 InterfaceAudience (org.apache.yetus.audience.InterfaceAudience)4 Arrays (java.util.Arrays)3 Map (java.util.Map)3 ServerMetrics (org.apache.hadoop.hbase.ServerMetrics)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 UserMetrics (org.apache.hadoop.hbase.UserMetrics)2 FieldValueType (org.apache.hadoop.hbase.hbtop.field.FieldValueType)2 Test (org.junit.Test)2