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();
}
}
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;
}
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());
}
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;
}
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;
}
Aggregations