Search in sources :

Example 1 with Statistic

use of com.linkedin.kafka.cruisecontrol.common.Statistic in project cruise-control by linkedin.

the class AnalyzerUtils method getJsonStructure.

/*
   * Return an object that can be further used
   * to encode into JSON
   *
   * @param clusterModelStats Cluster model stats.
   */
public static Map<String, Object> getJsonStructure(ClusterModelStats clusterModelStats) {
    Map<String, Object> clusterStatsMap = new HashMap<>();
    clusterStatsMap.put("brokers", clusterModelStats.numBrokers());
    clusterStatsMap.put("replicas", clusterModelStats.numReplicasInCluster());
    clusterStatsMap.put("topics", clusterModelStats.numTopics());
    Map<Statistic, Map<Resource, Double>> resourceUtilizationStats = clusterModelStats.resourceUtilizationStats();
    Map<Statistic, Double> nwOutUtilizationStats = clusterModelStats.potentialNwOutUtilizationStats();
    Map<Statistic, Number> replicaStats = clusterModelStats.replicaStats();
    Map<Statistic, Number> topicReplicaStats = clusterModelStats.topicReplicaStats();
    Map<String, Object> statisticMap = new HashMap<>();
    for (Statistic stat : Statistic.values()) {
        Map<String, Double> resourceMap = new HashMap<>();
        for (Resource resource : Resource.values()) {
            resourceMap.put(resource.resource(), resourceUtilizationStats.get(stat).get(resource));
        }
        resourceMap.put("potentialNwOut", nwOutUtilizationStats.get(stat));
        resourceMap.put("replicas", replicaStats.get(stat).doubleValue());
        resourceMap.put("topicReplicas", topicReplicaStats.get(stat).doubleValue());
        statisticMap.put(stat.stat(), resourceMap);
    }
    clusterStatsMap.put("statistics", statisticMap);
    return clusterStatsMap;
}
Also used : HashMap(java.util.HashMap) RawAndDerivedResource(com.linkedin.kafka.cruisecontrol.model.RawAndDerivedResource) Resource(com.linkedin.kafka.cruisecontrol.common.Resource) Statistic(com.linkedin.kafka.cruisecontrol.common.Statistic) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 2 with Statistic

use of com.linkedin.kafka.cruisecontrol.common.Statistic in project cruise-control by linkedin.

the class ClusterModelStats method getJsonStructure.

/*
   * Return an object that can be further used
   * to encode into JSON
   */
public Map<String, Object> getJsonStructure() {
    Map<String, Object> statMap = new HashMap<>();
    Map<String, Integer> basicMap = new HashMap<>();
    basicMap.put("brokers", numBrokers());
    basicMap.put("replicas", numReplicasInCluster());
    basicMap.put("topics", numTopics());
    // List of all statistics AVG, MAX, MIN, STD
    Map<String, Object> allStatMap = new HashMap();
    for (Statistic stat : Statistic.values()) {
        Map<String, Object> resourceMap = new HashMap<>();
        for (Resource resource : Resource.values()) {
            resourceMap.put(resource.resource(), resourceUtilizationStats().get(stat).get(resource));
        }
        resourceMap.put("potentialNwOut", potentialNwOutUtilizationStats().get(stat));
        resourceMap.put("replicas", replicaStats().get(stat));
        resourceMap.put("topicReplicas", topicReplicaStats().get(stat));
        allStatMap.put(stat.stat(), resourceMap);
    }
    statMap.put("metadata", basicMap);
    statMap.put("statistics", allStatMap);
    return statMap;
}
Also used : Statistic(com.linkedin.kafka.cruisecontrol.common.Statistic) HashMap(java.util.HashMap) Resource(com.linkedin.kafka.cruisecontrol.common.Resource)

Example 3 with Statistic

use of com.linkedin.kafka.cruisecontrol.common.Statistic in project cruise-control by linkedin.

the class ClusterModelStats method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append(String.format("brokers:%d replicas:%d topics:%d%n", numBrokers(), numReplicasInCluster(), numTopics()));
    for (Statistic stat : Statistic.values()) {
        sb.append(String.format("%s:{", stat));
        for (Resource resource : Resource.values()) {
            sb.append(String.format("%s:%12.3f ", resource, resourceUtilizationStats().get(stat).get(resource)));
        }
        sb.append(String.format("potentialNwOut:%12.3f replicas:%s topicReplicas:%s}%n", potentialNwOutUtilizationStats().get(stat), replicaStats().get(stat), topicReplicaStats().get(stat)));
    }
    return sb.substring(0, sb.length() - 2);
}
Also used : Statistic(com.linkedin.kafka.cruisecontrol.common.Statistic) Resource(com.linkedin.kafka.cruisecontrol.common.Resource)

Aggregations

Resource (com.linkedin.kafka.cruisecontrol.common.Resource)3 Statistic (com.linkedin.kafka.cruisecontrol.common.Statistic)3 HashMap (java.util.HashMap)2 RawAndDerivedResource (com.linkedin.kafka.cruisecontrol.model.RawAndDerivedResource)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1