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());
}
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;
}
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;
}
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();
}
}
}
Aggregations