Search in sources :

Example 6 with BrokerMetricSample

use of com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.BrokerMetricSample in project cruise-control by linkedin.

the class LinearRegressionModelParameters method addMetricObservation.

/**
 * Add metric observation with the given training data.
 *
 * @param trainingData Training data.
 */
public synchronized void addMetricObservation(Collection<BrokerMetricSample> trainingData) {
    if (trainingData != null) {
        for (BrokerMetricSample data : trainingData) {
            int utilBucket = (int) (data.metricValue(CPU_USAGE) / cpuUtilBucketSize);
            int index = INDICES.computeIfAbsent(utilBucket, k -> new AtomicInteger(0)).getAndIncrement() % numObservationsPerUtilBucket;
            double[][] byteRateObservations = BYTE_RATE_OBSERVATIONS.computeIfAbsent(utilBucket, k -> new double[numObservationsPerUtilBucket][]);
            double[] cpuUtilObservation = CPU_UTIL_OBSERVATIONS.computeIfAbsent(utilBucket, k -> new double[numObservationsPerUtilBucket]);
            byteRateObservations[index] = new double[] { data.metricValue(LEADER_BYTES_IN), data.metricValue(LEADER_BYTES_OUT), data.metricValue(REPLICATION_BYTES_IN_RATE) };
            cpuUtilObservation[index] = data.metricValue(CPU_USAGE);
            int leaderToFollowerBytesInRatio = data.metricValue(REPLICATION_BYTES_IN_RATE) == 0.0 ? 10000000 : (int) ((data.metricValue(LEADER_BYTES_IN) / data.metricValue(REPLICATION_BYTES_IN_RATE)) * 10);
            int leaderBytesInToBytesOutRatio = data.metricValue(LEADER_BYTES_OUT) == 0.0 ? 10000000 : (int) ((data.metricValue(LEADER_BYTES_IN) / data.metricValue(LEADER_BYTES_OUT)) * 10);
            int count = OBSERVED_LEADER_TO_FOLLOWER_BYTES_RATIO.getOrDefault(leaderToFollowerBytesInRatio, 0);
            OBSERVED_LEADER_TO_FOLLOWER_BYTES_RATIO.put(leaderToFollowerBytesInRatio, count + 1);
            count = OBSERVED_LEADER_BYTES_IN_TO_BYTES_OUT_RATIO.getOrDefault(leaderBytesInToBytesOutRatio, 0);
            OBSERVED_LEADER_BYTES_IN_TO_BYTES_OUT_RATIO.put(leaderBytesInToBytesOutRatio, count + 1);
            if (!COEFFICIENTS.isEmpty()) {
                Double estimatedCpu = data.metricValue(LEADER_BYTES_IN) * COEFFICIENTS.get(ModelCoefficient.LEADER_BYTES_IN) + data.metricValue(LEADER_BYTES_OUT) * COEFFICIENTS.getOrDefault(ModelCoefficient.LEADER_BYTES_OUT, 0.0) + data.metricValue(REPLICATION_BYTES_IN_RATE) * COEFFICIENTS.get(ModelCoefficient.FOLLOWER_BYTES_IN);
                int error = estimatedCpu.intValue() - data.metricValue(CPU_USAGE).intValue();
                count = CPU_UTIL_ESTIMATION_ERROR_STATS.getOrDefault(error, 0);
                CPU_UTIL_ESTIMATION_ERROR_STATS.put(error, count + 1);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("CPU util estimation: actual: {}, estimated: {}, error: {}", data.metricValue(CPU_USAGE), estimatedCpu, estimatedCpu - data.metricValue(CPU_USAGE));
                }
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BrokerMetricSample(com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.BrokerMetricSample)

Aggregations

BrokerMetricSample (com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.BrokerMetricSample)6 UnknownVersionException (com.linkedin.kafka.cruisecontrol.metricsreporter.exception.UnknownVersionException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Node (org.apache.kafka.common.Node)2 MetricDef (com.linkedin.cruisecontrol.metricdef.MetricDef)1 MetricInfo (com.linkedin.cruisecontrol.metricdef.MetricInfo)1 BrokerCapacityResolutionException (com.linkedin.kafka.cruisecontrol.exception.BrokerCapacityResolutionException)1 CruiseControlMetric (com.linkedin.kafka.cruisecontrol.metricsreporter.metric.CruiseControlMetric)1 RawMetricType (com.linkedin.kafka.cruisecontrol.metricsreporter.metric.RawMetricType)1 KafkaMetricDef (com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaMetricDef)1 SamplingUtils.buildBrokerMetricSample (com.linkedin.kafka.cruisecontrol.monitor.sampling.SamplingUtils.buildBrokerMetricSample)1 BrokerLoad (com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.BrokerLoad)1 PartitionMetricSample (com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.PartitionMetricSample)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 TimeoutException (java.util.concurrent.TimeoutException)1 Callback (org.apache.kafka.clients.producer.Callback)1 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)1