Search in sources :

Example 6 with CumulativeSum

use of org.apache.kafka.common.metrics.stats.CumulativeSum in project kafka by apache.

the class JmxReporterTest method testJmxRegistration.

@Test
public void testJmxRegistration() throws Exception {
    Metrics metrics = new Metrics();
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    try {
        JmxReporter reporter = new JmxReporter();
        metrics.addReporter(reporter);
        assertFalse(server.isRegistered(new ObjectName(":type=grp1")));
        Sensor sensor = metrics.sensor("kafka.requests");
        sensor.add(metrics.metricName("pack.bean1.avg", "grp1"), new Avg());
        sensor.add(metrics.metricName("pack.bean2.total", "grp2"), new CumulativeSum());
        assertTrue(server.isRegistered(new ObjectName(":type=grp1")));
        assertEquals(Double.NaN, server.getAttribute(new ObjectName(":type=grp1"), "pack.bean1.avg"));
        assertTrue(server.isRegistered(new ObjectName(":type=grp2")));
        assertEquals(0.0, server.getAttribute(new ObjectName(":type=grp2"), "pack.bean2.total"));
        MetricName metricName = metrics.metricName("pack.bean1.avg", "grp1");
        String mBeanName = JmxReporter.getMBeanName("", metricName);
        assertTrue(reporter.containsMbean(mBeanName));
        metrics.removeMetric(metricName);
        assertFalse(reporter.containsMbean(mBeanName));
        assertFalse(server.isRegistered(new ObjectName(":type=grp1")));
        assertTrue(server.isRegistered(new ObjectName(":type=grp2")));
        assertEquals(0.0, server.getAttribute(new ObjectName(":type=grp2"), "pack.bean2.total"));
        metricName = metrics.metricName("pack.bean2.total", "grp2");
        metrics.removeMetric(metricName);
        assertFalse(reporter.containsMbean(mBeanName));
        assertFalse(server.isRegistered(new ObjectName(":type=grp1")));
        assertFalse(server.isRegistered(new ObjectName(":type=grp2")));
    } finally {
        metrics.close();
    }
}
Also used : MetricName(org.apache.kafka.common.MetricName) CumulativeSum(org.apache.kafka.common.metrics.stats.CumulativeSum) Avg(org.apache.kafka.common.metrics.stats.Avg) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.jupiter.api.Test)

Example 7 with CumulativeSum

use of org.apache.kafka.common.metrics.stats.CumulativeSum in project kafka by apache.

the class KafkaProducerMetrics method newLatencySensor.

private Sensor newLatencySensor(String name, String description) {
    Sensor sensor = metrics.sensor(name + TOTAL_TIME_SUFFIX);
    sensor.add(metricName(name, description), new CumulativeSum());
    return sensor;
}
Also used : CumulativeSum(org.apache.kafka.common.metrics.stats.CumulativeSum) Sensor(org.apache.kafka.common.metrics.Sensor)

Example 8 with CumulativeSum

use of org.apache.kafka.common.metrics.stats.CumulativeSum in project kafka by apache.

the class StreamsMetricsImpl method addAvgAndSumMetricsToSensor.

public static void addAvgAndSumMetricsToSensor(final Sensor sensor, final String group, final Map<String, String> tags, final String metricNamePrefix, final String descriptionOfAvg, final String descriptionOfTotal) {
    sensor.add(new MetricName(metricNamePrefix + AVG_SUFFIX, group, descriptionOfAvg, tags), new Avg());
    sensor.add(new MetricName(metricNamePrefix + TOTAL_SUFFIX, group, descriptionOfTotal, tags), new CumulativeSum());
}
Also used : MetricName(org.apache.kafka.common.MetricName) CumulativeSum(org.apache.kafka.common.metrics.stats.CumulativeSum) Avg(org.apache.kafka.common.metrics.stats.Avg)

Example 9 with CumulativeSum

use of org.apache.kafka.common.metrics.stats.CumulativeSum in project kafka by apache.

the class StreamTaskTest method setupCloseTaskMetric.

private MetricName setupCloseTaskMetric() {
    final MetricName metricName = new MetricName("name", "group", "description", Collections.emptyMap());
    final Sensor sensor = streamsMetrics.threadLevelSensor(threadId, "task-closed", Sensor.RecordingLevel.INFO);
    sensor.add(metricName, new CumulativeSum());
    return metricName;
}
Also used : MetricName(org.apache.kafka.common.MetricName) CumulativeSum(org.apache.kafka.common.metrics.stats.CumulativeSum) Sensor(org.apache.kafka.common.metrics.Sensor)

Example 10 with CumulativeSum

use of org.apache.kafka.common.metrics.stats.CumulativeSum in project kafka by apache.

the class StandbyTaskTest method setupCloseTaskMetric.

private MetricName setupCloseTaskMetric() {
    final MetricName metricName = new MetricName("name", "group", "description", Collections.emptyMap());
    final Sensor sensor = streamsMetrics.threadLevelSensor(threadId, "task-closed", Sensor.RecordingLevel.INFO);
    sensor.add(metricName, new CumulativeSum());
    return metricName;
}
Also used : MetricName(org.apache.kafka.common.MetricName) CumulativeSum(org.apache.kafka.common.metrics.stats.CumulativeSum) Sensor(org.apache.kafka.common.metrics.Sensor)

Aggregations

CumulativeSum (org.apache.kafka.common.metrics.stats.CumulativeSum)10 Avg (org.apache.kafka.common.metrics.stats.Avg)5 Test (org.junit.jupiter.api.Test)5 MetricName (org.apache.kafka.common.MetricName)4 MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 Sensor (org.apache.kafka.common.metrics.Sensor)3 HashMap (java.util.HashMap)1 Max (org.apache.kafka.common.metrics.stats.Max)1 Meter (org.apache.kafka.common.metrics.stats.Meter)1 Min (org.apache.kafka.common.metrics.stats.Min)1 Percentile (org.apache.kafka.common.metrics.stats.Percentile)1 Percentiles (org.apache.kafka.common.metrics.stats.Percentiles)1 WindowedCount (org.apache.kafka.common.metrics.stats.WindowedCount)1