Search in sources :

Example 1 with SensorMetric

use of io.confluent.ksql.metrics.TopicSensors.SensorMetric in project ksql by confluentinc.

the class ConsumerCollector method buildSensors.

private List<SensorMetric<ConsumerRecord<Object, Object>>> buildSensors(final String key) {
    final List<SensorMetric<ConsumerRecord<Object, Object>>> sensors = new ArrayList<>();
    addSensor(key, CONSUMER_MESSAGES_PER_SEC, new Rate(), sensors, false);
    addSensor(key, CONSUMER_TOTAL_MESSAGES, new CumulativeSum(), sensors, false);
    addSensor(key, CONSUMER_TOTAL_BYTES, new CumulativeSum(), sensors, false, (r) -> {
        if (r == null) {
            return 0.0;
        } else {
            return ((double) r.serializedValueSize() + r.serializedKeySize());
        }
    });
    return sensors;
}
Also used : CumulativeSum(org.apache.kafka.common.metrics.stats.CumulativeSum) Rate(org.apache.kafka.common.metrics.stats.Rate) ArrayList(java.util.ArrayList) SensorMetric(io.confluent.ksql.metrics.TopicSensors.SensorMetric)

Example 2 with SensorMetric

use of io.confluent.ksql.metrics.TopicSensors.SensorMetric in project ksql by confluentinc.

the class ProducerCollector method buildSensors.

private List<SensorMetric<ProducerRecord<Object, Object>>> buildSensors(final String key) {
    final List<SensorMetric<ProducerRecord<Object, Object>>> sensors = new ArrayList<>();
    // activity in a reliable way
    synchronized (metrics) {
        addSensor(key, PRODUCER_MESSAGES_PER_SEC, new Rate(), sensors);
        addSensor(key, PRODUCER_TOTAL_MESSAGES, new CumulativeSum(), sensors);
    }
    return sensors;
}
Also used : CumulativeSum(org.apache.kafka.common.metrics.stats.CumulativeSum) Rate(org.apache.kafka.common.metrics.stats.Rate) ArrayList(java.util.ArrayList) SensorMetric(io.confluent.ksql.metrics.TopicSensors.SensorMetric)

Example 3 with SensorMetric

use of io.confluent.ksql.metrics.TopicSensors.SensorMetric in project ksql by confluentinc.

the class StreamsErrorCollector method buildSensor.

private SensorMetric<Object> buildSensor(final String key, final String metricNameString, final MeasurableStat stat, final Function<Object, Double> recordValue) {
    final String name = "sec-" + key + "-" + metricNameString + "-" + id;
    final MetricName metricName = new MetricName(metricNameString, "consumer-metrics", "consumer-" + name, ImmutableMap.of("key", key, "id", id));
    final Sensor sensor = metrics.sensor(name);
    sensor.add(metricName, stat);
    final KafkaMetric metric = metrics.metrics().get(metricName);
    return new TopicSensors.SensorMetric<Object>(sensor, metric, time, true) {

        void record(final Object o) {
            sensor.record(recordValue.apply(o));
            super.record(o);
        }
    };
}
Also used : MetricName(org.apache.kafka.common.MetricName) SensorMetric(io.confluent.ksql.metrics.TopicSensors.SensorMetric) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Sensor(org.apache.kafka.common.metrics.Sensor)

Aggregations

SensorMetric (io.confluent.ksql.metrics.TopicSensors.SensorMetric)3 ArrayList (java.util.ArrayList)2 CumulativeSum (org.apache.kafka.common.metrics.stats.CumulativeSum)2 Rate (org.apache.kafka.common.metrics.stats.Rate)2 MetricName (org.apache.kafka.common.MetricName)1 KafkaMetric (org.apache.kafka.common.metrics.KafkaMetric)1 Sensor (org.apache.kafka.common.metrics.Sensor)1