Search in sources :

Example 11 with MetricName

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

the class JmxReporter method addAttribute.

private KafkaMbean addAttribute(KafkaMetric metric) {
    try {
        MetricName metricName = metric.metricName();
        String mBeanName = getMBeanName(metricName);
        if (!this.mbeans.containsKey(mBeanName))
            mbeans.put(mBeanName, new KafkaMbean(mBeanName));
        KafkaMbean mbean = this.mbeans.get(mBeanName);
        mbean.setAttribute(metricName.name(), metric);
        return mbean;
    } catch (JMException e) {
        throw new KafkaException("Error creating mbean attribute for metricName :" + metric.metricName(), e);
    }
}
Also used : MetricName(org.apache.kafka.common.MetricName) JMException(javax.management.JMException) KafkaException(org.apache.kafka.common.KafkaException)

Example 12 with MetricName

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

the class Metrics method registerMetric.

synchronized void registerMetric(KafkaMetric metric) {
    MetricName metricName = metric.metricName();
    if (this.metrics.containsKey(metricName))
        throw new IllegalArgumentException("A metric named '" + metricName + "' already exists, can't register another one.");
    this.metrics.put(metricName, metric);
    for (MetricsReporter reporter : reporters) reporter.metricChange(metric);
}
Also used : MetricName(org.apache.kafka.common.MetricName)

Example 13 with MetricName

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

the class StreamsMetricsImplTest method testThroughputMetrics.

@Test
public void testThroughputMetrics() {
    String groupName = "doesNotMatter";
    String scope = "scope";
    String entity = "entity";
    String operation = "put";
    Map<String, String> tags = new HashMap<>();
    StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(new Metrics(), groupName, tags);
    Sensor sensor1 = streamsMetrics.addThroughputSensor(scope, entity, operation, Sensor.RecordingLevel.DEBUG);
    Map<MetricName, ? extends Metric> metrics = streamsMetrics.metrics();
    // 2 metrics plus a common metric that keeps track of total registered metrics in Metrics() constructor
    assertEquals(metrics.size(), 3);
    streamsMetrics.removeSensor(sensor1);
    metrics = streamsMetrics.metrics();
    assertEquals(metrics.size(), 1);
}
Also used : MetricName(org.apache.kafka.common.MetricName) Metrics(org.apache.kafka.common.metrics.Metrics) HashMap(java.util.HashMap) Sensor(org.apache.kafka.common.metrics.Sensor) Test(org.junit.Test)

Aggregations

MetricName (org.apache.kafka.common.MetricName)13 Test (org.junit.Test)6 Sensor (org.apache.kafka.common.metrics.Sensor)4 HashMap (java.util.HashMap)3 KafkaMetric (org.apache.kafka.common.metrics.KafkaMetric)3 Metrics (org.apache.kafka.common.metrics.Metrics)3 Map (java.util.Map)2 KafkaMetricWrapper (org.apache.flink.streaming.connectors.kafka.internals.metrics.KafkaMetricWrapper)2 MemoryRecordsBuilder (org.apache.kafka.common.record.MemoryRecordsBuilder)2 ArrayList (java.util.ArrayList)1 JMException (javax.management.JMException)1 RuntimeContext (org.apache.flink.api.common.functions.RuntimeContext)1 MetricGroup (org.apache.flink.metrics.MetricGroup)1 StreamingRuntimeContext (org.apache.flink.streaming.api.operators.StreamingRuntimeContext)1 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)1 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)1 OffsetCommitCallback (org.apache.kafka.clients.consumer.OffsetCommitCallback)1 Callback (org.apache.kafka.clients.producer.Callback)1 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)1 KafkaException (org.apache.kafka.common.KafkaException)1