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