use of com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues in project cruise-control by linkedin.
the class PreferredLeaderElectionGoalTest method createReplicaAndSetLoad.
private void createReplicaAndSetLoad(ClusterModel clusterModel, String rack, int brokerId, TopicPartition tp, int index, boolean isLeader) {
clusterModel.createReplica(rack, brokerId, tp, index, isLeader);
MetricValues metricValues = new MetricValues(1);
Map<Integer, MetricValues> metricValuesByResource = new HashMap<>();
Resource.cachedValues().forEach(r -> metricValuesByResource.put(KafkaCruiseControlMetricDef.resourceToMetricId(r), metricValues));
clusterModel.setReplicaLoad(rack, brokerId, tp, new AggregatedMetricValues(metricValuesByResource), Collections.singletonList(1L));
}
use of com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues in project cruise-control by linkedin.
the class Load method loadFor.
/**
* Get the load for the requested resource cross all the windows.
*
* @param resource Resource for which the load will be provided.
* @return Load of the requested resource as a mapping from snapshot time to utilization for the given resource.
*/
MetricValues loadFor(Resource resource) {
MetricValues loadForResource = new MetricValues(_metricValues.length());
loadForResource.add(_metricValues.valuesFor(KafkaCruiseControlMetricDef.resourceToMetricId(resource)));
return loadForResource;
}
use of com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues in project cruise-control by linkedin.
the class Replica method makeFollower.
/**
* (1) Remove leadership from the replica.
* (2) Clear and get the outbound network load associated with leadership from the given replica.
* (3) Clear and get the CPU leadership load associated with leadership from the given replica.
*
* @return Removed leadership load by snapshot time -- i.e. outbound network and fraction of CPU load by snapshot time.
*/
Map<Resource, double[]> makeFollower() {
// Remove leadership from the replica.
setLeadership(false);
// Clear and get the outbound network load associated with leadership from the given replica.
double[] leadershipNwOutLoad = _load.loadFor(Resource.NW_OUT).doubleArray();
MetricValues leadershipCpuLoad = _load.loadFor(Resource.CPU);
// Remove the outbound network leadership load from replica.
_load.clearLoadFor(Resource.NW_OUT);
double[] followerCpuLoad = new double[_load.numWindows()];
double[] cpuLoadChange = new double[_load.numWindows()];
for (int i = 0; i < leadershipCpuLoad.length(); i++) {
double newCpuLoad = ModelUtils.getFollowerCpuUtilFromLeaderLoad(_load.loadFor(Resource.NW_IN).get(i), _load.loadFor(Resource.NW_OUT).get(i), leadershipCpuLoad.get(i));
followerCpuLoad[i] = newCpuLoad;
cpuLoadChange[i] = leadershipCpuLoad.get(i) - newCpuLoad;
}
_load.setLoadFor(Resource.CPU, followerCpuLoad);
// Get the change of the load for upper layer.
Map<Resource, double[]> leadershipLoad = new HashMap<>();
leadershipLoad.put(Resource.NW_OUT, leadershipNwOutLoad);
leadershipLoad.put(Resource.CPU, cpuLoadChange);
// Return removed leadership load.
return leadershipLoad;
}
use of com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues in project cruise-control by linkedin.
the class KafkaCruiseControlUnitTestUtils method getAggregatedMetricValues.
/**
* Get the aggregated metric values with the given resource usage.
*/
public static AggregatedMetricValues getAggregatedMetricValues(double cpuUsage, double networkInBoundUsage, double networkOutBoundUsage, double diskUsage) {
double[] values = new double[Resource.cachedValues().size()];
values[KafkaCruiseControlMetricDef.resourceToMetricId(CPU)] = cpuUsage;
values[KafkaCruiseControlMetricDef.resourceToMetricId(NW_IN)] = networkInBoundUsage;
values[KafkaCruiseControlMetricDef.resourceToMetricId(NW_OUT)] = networkOutBoundUsage;
values[KafkaCruiseControlMetricDef.resourceToMetricId(DISK)] = diskUsage;
AggregatedMetricValues aggregateMetricValues = new AggregatedMetricValues();
for (Resource r : Resource.cachedValues()) {
int metricId = KafkaCruiseControlMetricDef.resourceToMetricId(r);
MetricValues metricValues = new MetricValues(1);
metricValues.set(0, values[metricId]);
aggregateMetricValues.add(metricId, metricValues);
}
return aggregateMetricValues;
}
use of com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues in project cruise-control by linkedin.
the class DeterministicCluster method createLoad.
private static AggregatedMetricValues createLoad(double cpu, double networkIn, double networkOut, double disk) {
AggregatedMetricValues aggregatedMetricValues = new AggregatedMetricValues();
MetricValues metricValues = new MetricValues(1);
metricValues.set(0, cpu);
aggregatedMetricValues.add(KafkaCruiseControlMetricDef.resourceToMetricId(Resource.CPU), metricValues);
metricValues = new MetricValues(1);
metricValues.set(0, networkIn);
aggregatedMetricValues.add(KafkaCruiseControlMetricDef.resourceToMetricId(Resource.NW_IN), metricValues);
metricValues = new MetricValues(1);
metricValues.set(0, networkOut);
aggregatedMetricValues.add(KafkaCruiseControlMetricDef.resourceToMetricId(Resource.NW_OUT), metricValues);
metricValues = new MetricValues(1);
metricValues.set(0, disk);
aggregatedMetricValues.add(KafkaCruiseControlMetricDef.resourceToMetricId(Resource.DISK), metricValues);
return aggregatedMetricValues;
}
Aggregations