Search in sources :

Example 1 with BrokerMetric

use of com.linkedin.kafka.cruisecontrol.metricsreporter.metric.BrokerMetric in project cruise-control by linkedin.

the class CruiseControlMetricsProcessorTest method testBrokerMetricInvalid.

@Test
public void testBrokerMetricInvalid() {
    CruiseControlMetricsProcessor processor = new CruiseControlMetricsProcessor();
    Set<CruiseControlMetric> metrics = getCruiseControlMetrics();
    for (CruiseControlMetric metric : metrics) {
        if (metric.metricType() == MetricType.ALL_TOPIC_BYTES_IN && metric.brokerId() == BROKER_ID_0) {
            processor.addMetric(new BrokerMetric(MetricType.ALL_TOPIC_BYTES_IN, _time.milliseconds(), BROKER_ID_0, 1000.0));
        } else {
            processor.addMetric(metric);
        }
    }
    MetricSampler.Samples samples = processor.process(getCluster(), Arrays.asList(T1P0, T1P1, T2P0, T2P1), MetricSampler.SamplingMode.ALL, METRIC_DEF);
    assertEquals("Should have ignored partitions on broker 0", 1, samples.partitionMetricSamples().size());
    assertEquals("Should have ignored broker 0", 1, samples.brokerMetricSamples().size());
}
Also used : CruiseControlMetric(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.CruiseControlMetric) BrokerMetric(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.BrokerMetric) Test(org.junit.Test)

Example 2 with BrokerMetric

use of com.linkedin.kafka.cruisecontrol.metricsreporter.metric.BrokerMetric in project cruise-control by linkedin.

the class PrometheusMetricSampler method addBrokerMetrics.

private int addBrokerMetrics(Cluster cluster, RawMetricType metricType, PrometheusQueryResult queryResult) throws InvalidPrometheusResultException {
    int brokerId = getBrokerId(cluster, queryResult);
    int metricsAdded = 0;
    for (PrometheusValue value : queryResult.values()) {
        addMetricForProcessing(new BrokerMetric(metricType, value.epochSeconds() * SEC_TO_MS, brokerId, value.value()));
        metricsAdded++;
    }
    return metricsAdded;
}
Also used : BrokerMetric(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.BrokerMetric) PrometheusValue(com.linkedin.kafka.cruisecontrol.monitor.sampling.prometheus.model.PrometheusValue)

Example 3 with BrokerMetric

use of com.linkedin.kafka.cruisecontrol.metricsreporter.metric.BrokerMetric in project cruise-control by linkedin.

the class CruiseControlMetricsProcessorTest method getCruiseControlMetrics.

/**
 * <ul>
 * <li>T1P0(B0): NW_IN = {@link #B0_TOPIC1_BYTES_IN} KB, NW_OUT = {@link #B0_TOPIC1_BYTES_OUT} KB,
 * size = {@link #T1P0_BYTES_SIZE} MB</li>
 * <li>T1P1(B1): NW_IN = {@link #B1_TOPIC1_BYTES_IN} KB, NW_OUT = {@link #B1_TOPIC1_BYTES_OUT} KB,
 * size = {@link #T1P1_BYTES_SIZE} MB</li>
 * <li>T2P0(B0): NW_IN = est. {@link #B0_TOPIC2_BYTES_IN}/2 KB, NW_OUT = est. {@link #B0_TOPIC2_BYTES_OUT}/2 KB,
 * size = {@link #T2P0_BYTES_SIZE} MB</li>
 * <li>T2P1(B0): NW_IN = est. {@link #B0_TOPIC2_BYTES_IN}/2 KB, NW_OUT = est. {@link #B0_TOPIC2_BYTES_OUT}/2 KB,
 * size = {@link #T2P1_BYTES_SIZE} MB</li>
 * <li>B0: CPU = {@link #B0_CPU}%</li>
 * <li>B1: CPU = {@link #B1_CPU}%</li>
 * </ul>
 * @return Cruise Control metrics.
 */
private Set<CruiseControlMetric> getCruiseControlMetrics() {
    Set<CruiseControlMetric> metrics = new HashSet<>();
    int i = 0;
    for (RawMetricType rawMetricType : RawMetricType.brokerMetricTypesDiffForVersion(BrokerMetricSample.MIN_SUPPORTED_VERSION)) {
        switch(rawMetricType) {
            case ALL_TOPIC_BYTES_IN:
                metrics.add(new BrokerMetric(RawMetricType.ALL_TOPIC_BYTES_IN, _time.milliseconds(), BROKER_ID_0, B0_ALL_TOPIC_BYTES_IN * BYTES_IN_KB));
                metrics.add(new BrokerMetric(RawMetricType.ALL_TOPIC_BYTES_IN, _time.milliseconds(), BROKER_ID_1, B1_ALL_TOPIC_BYTES_IN * BYTES_IN_KB));
                break;
            case ALL_TOPIC_BYTES_OUT:
                metrics.add(new BrokerMetric(RawMetricType.ALL_TOPIC_BYTES_OUT, _time.milliseconds(), BROKER_ID_0, B0_ALL_TOPIC_BYTES_OUT * BYTES_IN_KB));
                metrics.add(new BrokerMetric(RawMetricType.ALL_TOPIC_BYTES_OUT, _time.milliseconds(), BROKER_ID_1, B1_ALL_TOPIC_BYTES_OUT * BYTES_IN_KB));
                break;
            case BROKER_CPU_UTIL:
                metrics.add(new BrokerMetric(RawMetricType.BROKER_CPU_UTIL, _time.milliseconds(), BROKER_ID_0, B0_CPU));
                metrics.add(new BrokerMetric(RawMetricType.BROKER_CPU_UTIL, _time.milliseconds(), BROKER_ID_1, B1_CPU));
                break;
            default:
                metrics.add(new BrokerMetric(rawMetricType, _time.milliseconds(), BROKER_ID_0, i++ * BYTES_IN_MB));
                metrics.add(new BrokerMetric(rawMetricType, _time.milliseconds(), BROKER_ID_1, i++ * BYTES_IN_MB));
                break;
        }
    }
    for (RawMetricType rawMetricType : RawMetricType.topicMetricTypes()) {
        switch(rawMetricType) {
            case TOPIC_BYTES_IN:
                metrics.add(new TopicMetric(TOPIC_BYTES_IN, _time.milliseconds() + 1, BROKER_ID_0, TOPIC1, B0_TOPIC1_BYTES_IN * BYTES_IN_KB));
                metrics.add(new TopicMetric(TOPIC_BYTES_IN, _time.milliseconds() + 2, BROKER_ID_1, TOPIC1, B1_TOPIC1_BYTES_IN * BYTES_IN_KB));
                metrics.add(new TopicMetric(TOPIC_BYTES_IN, _time.milliseconds(), BROKER_ID_0, TOPIC2, B0_TOPIC2_BYTES_IN * BYTES_IN_KB));
                break;
            case TOPIC_BYTES_OUT:
                metrics.add(new TopicMetric(RawMetricType.TOPIC_BYTES_OUT, _time.milliseconds(), BROKER_ID_0, TOPIC1, B0_TOPIC1_BYTES_OUT * BYTES_IN_KB));
                metrics.add(new TopicMetric(RawMetricType.TOPIC_BYTES_OUT, _time.milliseconds(), BROKER_ID_1, TOPIC1, B1_TOPIC1_BYTES_OUT * BYTES_IN_KB));
                metrics.add(new TopicMetric(RawMetricType.TOPIC_BYTES_OUT, _time.milliseconds(), BROKER_ID_0, TOPIC2, B0_TOPIC2_BYTES_OUT * BYTES_IN_KB));
                break;
            case TOPIC_REPLICATION_BYTES_IN:
                metrics.add(new TopicMetric(RawMetricType.TOPIC_REPLICATION_BYTES_IN, _time.milliseconds(), BROKER_ID_1, TOPIC1, B1_TOPIC1_REPLICATION_BYTES_IN * BYTES_IN_KB));
                metrics.add(new TopicMetric(RawMetricType.TOPIC_REPLICATION_BYTES_IN, _time.milliseconds(), BROKER_ID_0, TOPIC1, B0_TOPIC1_REPLICATION_BYTES_IN * BYTES_IN_KB));
                metrics.add(new TopicMetric(RawMetricType.TOPIC_REPLICATION_BYTES_IN, _time.milliseconds(), BROKER_ID_1, TOPIC2, B1_TOPIC2_REPLICATION_BYTES_IN * BYTES_IN_KB));
                break;
            case TOPIC_REPLICATION_BYTES_OUT:
                metrics.add(new TopicMetric(RawMetricType.TOPIC_REPLICATION_BYTES_OUT, _time.milliseconds(), BROKER_ID_0, TOPIC1, B0_TOPIC1_REPLICATION_BYTES_OUT * BYTES_IN_KB));
                metrics.add(new TopicMetric(RawMetricType.TOPIC_REPLICATION_BYTES_OUT, _time.milliseconds(), BROKER_ID_1, TOPIC1, B1_TOPIC1_REPLICATION_BYTES_OUT * BYTES_IN_KB));
                metrics.add(new TopicMetric(RawMetricType.TOPIC_REPLICATION_BYTES_OUT, _time.milliseconds(), BROKER_ID_0, TOPIC2, B0_TOPIC2_REPLICATION_BYTES_OUT * BYTES_IN_KB));
                break;
            default:
                metrics.add(new TopicMetric(rawMetricType, _time.milliseconds(), BROKER_ID_0, TOPIC1, i * BYTES_IN_MB));
                metrics.add(new TopicMetric(rawMetricType, _time.milliseconds(), BROKER_ID_1, TOPIC1, i * BYTES_IN_MB));
                metrics.add(new TopicMetric(rawMetricType, _time.milliseconds(), BROKER_ID_0, TOPIC2, i * BYTES_IN_MB));
                metrics.add(new TopicMetric(rawMetricType, _time.milliseconds(), BROKER_ID_1, TOPIC2, i * BYTES_IN_MB));
                break;
        }
    }
    metrics.add(new PartitionMetric(RawMetricType.PARTITION_SIZE, _time.milliseconds(), BROKER_ID_0, TOPIC1, P0, T1P0_BYTES_SIZE * BYTES_IN_MB));
    metrics.add(new PartitionMetric(RawMetricType.PARTITION_SIZE, _time.milliseconds(), BROKER_ID_0, TOPIC1, P1, T1P1_BYTES_SIZE * BYTES_IN_MB));
    metrics.add(new PartitionMetric(RawMetricType.PARTITION_SIZE, _time.milliseconds(), BROKER_ID_0, TOPIC2, P0, T2P0_BYTES_SIZE * BYTES_IN_MB));
    metrics.add(new PartitionMetric(RawMetricType.PARTITION_SIZE, _time.milliseconds(), BROKER_ID_0, TOPIC2, P1, T2P1_BYTES_SIZE * BYTES_IN_MB));
    metrics.add(new PartitionMetric(RawMetricType.PARTITION_SIZE, _time.milliseconds(), BROKER_ID_1, TOPIC1, P0, T1P0_BYTES_SIZE * BYTES_IN_MB));
    metrics.add(new PartitionMetric(RawMetricType.PARTITION_SIZE, _time.milliseconds(), BROKER_ID_1, TOPIC1, P1, T1P1_BYTES_SIZE * BYTES_IN_MB));
    metrics.add(new PartitionMetric(RawMetricType.PARTITION_SIZE, _time.milliseconds(), BROKER_ID_1, TOPIC2, P0, T2P0_BYTES_SIZE * BYTES_IN_MB));
    metrics.add(new PartitionMetric(RawMetricType.PARTITION_SIZE, _time.milliseconds(), BROKER_ID_1, TOPIC2, P1, T2P1_BYTES_SIZE * BYTES_IN_MB));
    return metrics;
}
Also used : CruiseControlMetric(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.CruiseControlMetric) RawMetricType(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.RawMetricType) BrokerMetric(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.BrokerMetric) PartitionMetric(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.PartitionMetric) TopicMetric(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.TopicMetric) HashSet(java.util.HashSet)

Aggregations

BrokerMetric (com.linkedin.kafka.cruisecontrol.metricsreporter.metric.BrokerMetric)3 CruiseControlMetric (com.linkedin.kafka.cruisecontrol.metricsreporter.metric.CruiseControlMetric)2 PartitionMetric (com.linkedin.kafka.cruisecontrol.metricsreporter.metric.PartitionMetric)1 RawMetricType (com.linkedin.kafka.cruisecontrol.metricsreporter.metric.RawMetricType)1 TopicMetric (com.linkedin.kafka.cruisecontrol.metricsreporter.metric.TopicMetric)1 PrometheusValue (com.linkedin.kafka.cruisecontrol.monitor.sampling.prometheus.model.PrometheusValue)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1