Search in sources :

Example 1 with MetricValues

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));
}
Also used : HashMap(java.util.HashMap) MetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues) AggregatedMetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues) AggregatedMetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues)

Example 2 with MetricValues

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;
}
Also used : MetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues) AggregatedMetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues)

Example 3 with MetricValues

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;
}
Also used : HashMap(java.util.HashMap) Resource(com.linkedin.kafka.cruisecontrol.common.Resource) AggregatedMetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues) MetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues)

Example 4 with MetricValues

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;
}
Also used : Resource(com.linkedin.kafka.cruisecontrol.common.Resource) MetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues) AggregatedMetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues) AggregatedMetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues)

Example 5 with MetricValues

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;
}
Also used : AggregatedMetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues) MetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues) AggregatedMetricValues(com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues)

Aggregations

AggregatedMetricValues (com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues)8 MetricValues (com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues)8 HashMap (java.util.HashMap)4 Resource (com.linkedin.kafka.cruisecontrol.common.Resource)2 ArrayList (java.util.ArrayList)2 MetricDef (com.linkedin.cruisecontrol.metricdef.MetricDef)1 MetricInfo (com.linkedin.cruisecontrol.metricdef.MetricInfo)1 Partition (com.linkedin.kafka.cruisecontrol.model.Partition)1 KafkaCruiseControlMetricDef (com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 TopicPartition (org.apache.kafka.common.TopicPartition)1