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