Search in sources :

Example 6 with NamedMeasurable

use of org.apache.kafka.common.metrics.CompoundStat.NamedMeasurable in project kafka by apache.

the class Sensor method add.

/**
 * Register a compound statistic with this sensor which yields multiple measurable quantities (like a histogram)
 * @param stat The stat to register
 * @param config The configuration for this stat. If null then the stat will use the default configuration for this
 *        sensor.
 * @return true if stat is added to sensor, false if sensor is expired
 */
public synchronized boolean add(CompoundStat stat, MetricConfig config) {
    if (hasExpired())
        return false;
    final MetricConfig statConfig = config == null ? this.config : config;
    stats.add(new StatAndConfig(Objects.requireNonNull(stat), () -> statConfig));
    Object lock = metricLock();
    for (NamedMeasurable m : stat.stats()) {
        final KafkaMetric metric = new KafkaMetric(lock, m.name(), m.stat(), statConfig, time);
        if (!metrics.containsKey(metric.metricName())) {
            registry.registerMetric(metric);
            metrics.put(metric.metricName(), metric);
        }
    }
    return true;
}
Also used : NamedMeasurable(org.apache.kafka.common.metrics.CompoundStat.NamedMeasurable)

Aggregations

NamedMeasurable (org.apache.kafka.common.metrics.CompoundStat.NamedMeasurable)6 MetricName (org.apache.kafka.common.MetricName)4 MetricConfig (org.apache.kafka.common.metrics.MetricConfig)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2