use of com.linkedin.cruisecontrol.metricdef.MetricDef in project cruise-control by linkedin.
the class PartitionMetricSample method toBytes.
/**
* This method serialize the metric sample using a simple protocol.
* 1 byte - version
* 4 bytes - brokerId
* 8 bytes - CPU Utilization
* 8 bytes - DISK Utilization
* 8 bytes - Network Inbound Utilization
* 8 bytes - Network Outbound Utilization.
* 8 bytes - Produce Request Rate
* 8 bytes - Fetch Request Rate
* 8 bytes - Messages In Per Sec
* 8 bytes - Replication Bytes In Per Sec
* 8 bytes - Replication Bytes Out Per Sec
* 8 bytes - Sample time
* 4 bytes - partition id
* N bytes - topic string bytes
*/
public byte[] toBytes() {
MetricDef metricDef = KafkaCruiseControlMetricDef.metricDef();
byte[] topicStringBytes = entity().group().getBytes(UTF_8);
// Allocate memory:
ByteBuffer buffer = ByteBuffer.allocate(89 + topicStringBytes.length);
buffer.put(CURRENT_VERSION);
buffer.putInt(_brokerId);
buffer.putDouble(_valuesByMetricId.get(metricDef.metricInfo(CPU_USAGE.name()).id()));
buffer.putDouble(_valuesByMetricId.get(metricDef.metricInfo(DISK_USAGE.name()).id()));
buffer.putDouble(_valuesByMetricId.get(metricDef.metricInfo(LEADER_BYTES_IN.name()).id()));
buffer.putDouble(_valuesByMetricId.get(metricDef.metricInfo(LEADER_BYTES_OUT.name()).id()));
buffer.putDouble(_valuesByMetricId.get(metricDef.metricInfo(PRODUCE_RATE.name()).id()));
buffer.putDouble(_valuesByMetricId.get(metricDef.metricInfo(FETCH_RATE.name()).id()));
buffer.putDouble(_valuesByMetricId.get(metricDef.metricInfo(MESSAGE_IN_RATE.name()).id()));
buffer.putDouble(_valuesByMetricId.get(metricDef.metricInfo(REPLICATION_BYTES_IN_RATE.name()).id()));
buffer.putDouble(_valuesByMetricId.get(metricDef.metricInfo(REPLICATION_BYTES_OUT_RATE.name()).id()));
buffer.putLong(_sampleTime);
buffer.putInt(entity().tp().partition());
buffer.put(topicStringBytes);
return buffer.array();
}
use of com.linkedin.cruisecontrol.metricdef.MetricDef in project cruise-control by linkedin.
the class Load method getJsonStructure.
/**
* Return an object that can be further used
* to encode into JSON
*/
public Map<String, Object> getJsonStructure() {
MetricDef metricDef = KafkaCruiseControlMetricDef.metricDef();
Map<String, Object> loadMap = new HashMap<>();
List<Object> metricValueList = new ArrayList<>();
for (MetricInfo metricInfo : metricDef.all()) {
MetricValues metricValues = _metricValues.valuesFor(metricInfo.id());
if (metricValues != null) {
Map<Long, Double> metricValuesMap = new HashMap<>();
for (int i = 0; i < _windows.size(); i++) {
metricValuesMap.put(_windows.get(i), metricValues.get(i));
}
metricValueList.add(metricValuesMap);
}
}
loadMap.put("MetricValues", metricValueList);
return loadMap;
}
Aggregations