Search in sources :

Example 6 with MetricDef

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();
}
Also used : KafkaCruiseControlMetricDef(com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef) MetricDef(com.linkedin.cruisecontrol.metricdef.MetricDef) ByteBuffer(java.nio.ByteBuffer)

Example 7 with MetricDef

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;
}
Also used : HashMap(java.util.HashMap) KafkaCruiseControlMetricDef(com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef) MetricDef(com.linkedin.cruisecontrol.metricdef.MetricDef) ArrayList(java.util.ArrayList) MetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues) AggregatedMetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues) MetricInfo(com.linkedin.cruisecontrol.metricdef.MetricInfo)

Aggregations

MetricDef (com.linkedin.cruisecontrol.metricdef.MetricDef)7 KafkaCruiseControlMetricDef (com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef)7 TopicPartition (org.apache.kafka.common.TopicPartition)3 Resource (com.linkedin.kafka.cruisecontrol.common.Resource)2 Test (org.junit.Test)2 MetricInfo (com.linkedin.cruisecontrol.metricdef.MetricInfo)1 AggregatedMetricValues (com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues)1 MetricValues (com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues)1 ValuesAndExtrapolations (com.linkedin.cruisecontrol.monitor.sampling.aggregator.ValuesAndExtrapolations)1 OperationProgress (com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress)1 KafkaCruiseControlConfig (com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig)1 PartitionEntity (com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity)1 PartitionMetricSample (com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionMetricSample)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Metadata (org.apache.kafka.clients.Metadata)1