Search in sources :

Example 41 with Metric

use of org.apache.kafka.common.Metric in project kafka by apache.

the class StreamsProducerTest method addMetric.

private void addMetric(final MockProducer<?, ?> producer, final String name, final double value) {
    final MetricName metricName = metricName(name);
    producer.setMockMetrics(metricName, new Metric() {

        @Override
        public MetricName metricName() {
            return metricName;
        }

        @Override
        public Object metricValue() {
            return value;
        }
    });
}
Also used : MetricName(org.apache.kafka.common.MetricName) Metric(org.apache.kafka.common.Metric)

Example 42 with Metric

use of org.apache.kafka.common.Metric in project flink by apache.

the class KafkaWriter method computeSendTime.

private long computeSendTime() {
    FlinkKafkaInternalProducer<byte[], byte[]> producer = this.currentProducer;
    if (producer == null) {
        return -1L;
    }
    final Metric sendTime = MetricUtil.getKafkaMetric(producer.metrics(), KAFKA_PRODUCER_METRICS, "request-latency-avg");
    final Metric queueTime = MetricUtil.getKafkaMetric(producer.metrics(), KAFKA_PRODUCER_METRICS, "record-queue-time-avg");
    return ((Number) sendTime.metricValue()).longValue() + ((Number) queueTime.metricValue()).longValue();
}
Also used : Metric(org.apache.kafka.common.Metric)

Aggregations

Metric (org.apache.kafka.common.Metric)42 MetricName (org.apache.kafka.common.MetricName)24 Test (org.junit.Test)18 MockTime (org.apache.kafka.common.utils.MockTime)14 StreamsConfig (org.apache.kafka.streams.StreamsConfig)13 Map (java.util.Map)11 Test (org.junit.jupiter.api.Test)11 Metrics (org.apache.kafka.common.metrics.Metrics)10 Collections (java.util.Collections)9 HashMap (java.util.HashMap)9 Properties (java.util.Properties)9 KafkaMetric (org.apache.kafka.common.metrics.KafkaMetric)9 StreamsMetricsImpl (org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl)9 ArrayList (java.util.ArrayList)8 TaskId (org.apache.kafka.streams.processor.TaskId)8 List (java.util.List)7 TopicPartition (org.apache.kafka.common.TopicPartition)7 StreamsException (org.apache.kafka.streams.errors.StreamsException)7 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)7 Utils.mkMap (org.apache.kafka.common.utils.Utils.mkMap)6