use of org.apache.kafka.common.metrics.MetricsContext in project kafka by apache.
the class KafkaConsumer method buildMetrics.
private static Metrics buildMetrics(ConsumerConfig config, Time time, String clientId) {
Map<String, String> metricsTags = Collections.singletonMap(CLIENT_ID_METRIC_TAG, clientId);
MetricConfig metricConfig = new MetricConfig().samples(config.getInt(ConsumerConfig.METRICS_NUM_SAMPLES_CONFIG)).timeWindow(config.getLong(ConsumerConfig.METRICS_SAMPLE_WINDOW_MS_CONFIG), TimeUnit.MILLISECONDS).recordLevel(Sensor.RecordingLevel.forName(config.getString(ConsumerConfig.METRICS_RECORDING_LEVEL_CONFIG))).tags(metricsTags);
List<MetricsReporter> reporters = config.getConfiguredInstances(ConsumerConfig.METRIC_REPORTER_CLASSES_CONFIG, MetricsReporter.class, Collections.singletonMap(ConsumerConfig.CLIENT_ID_CONFIG, clientId));
JmxReporter jmxReporter = new JmxReporter();
jmxReporter.configure(config.originals(Collections.singletonMap(ConsumerConfig.CLIENT_ID_CONFIG, clientId)));
reporters.add(jmxReporter);
MetricsContext metricsContext = new KafkaMetricsContext(JMX_PREFIX, config.originalsWithPrefix(CommonClientConfigs.METRICS_CONTEXT_PREFIX));
return new Metrics(metricConfig, reporters, time, metricsContext);
}
use of org.apache.kafka.common.metrics.MetricsContext in project kafka by apache.
the class MirrorConnectorConfig method metricsReporters.
List<MetricsReporter> metricsReporters() {
List<MetricsReporter> reporters = getConfiguredInstances(CommonClientConfigs.METRIC_REPORTER_CLASSES_CONFIG, MetricsReporter.class);
JmxReporter jmxReporter = new JmxReporter();
jmxReporter.configure(this.originals());
reporters.add(jmxReporter);
MetricsContext metricsContext = new KafkaMetricsContext("kafka.connect.mirror");
for (MetricsReporter reporter : reporters) {
reporter.contextChange(metricsContext);
}
return reporters;
}
use of org.apache.kafka.common.metrics.MetricsContext in project kafka by apache.
the class MeteredWindowStoreTest method testMetrics.
@Test
public void testMetrics() {
replay(innerStoreMock);
store.init((StateStoreContext) context, store);
final JmxReporter reporter = new JmxReporter();
final MetricsContext metricsContext = new KafkaMetricsContext("kafka.streams");
reporter.contextChange(metricsContext);
metrics.addReporter(reporter);
assertTrue(reporter.containsMbean(String.format("kafka.streams:type=%s,%s=%s,task-id=%s,%s-state-id=%s", STORE_LEVEL_GROUP, THREAD_ID_TAG_KEY, threadId, context.taskId().toString(), STORE_TYPE, STORE_NAME)));
}
use of org.apache.kafka.common.metrics.MetricsContext in project kafka by apache.
the class MeteredSessionStoreTest method testMetrics.
@Test
public void testMetrics() {
init();
final JmxReporter reporter = new JmxReporter();
final MetricsContext metricsContext = new KafkaMetricsContext("kafka.streams");
reporter.contextChange(metricsContext);
metrics.addReporter(reporter);
assertTrue(reporter.containsMbean(String.format("kafka.streams:type=%s,%s=%s,task-id=%s,%s-state-id=%s", STORE_LEVEL_GROUP, THREAD_ID_TAG_KEY, threadId, taskId.toString(), STORE_TYPE, STORE_NAME)));
}
use of org.apache.kafka.common.metrics.MetricsContext in project kafka by apache.
the class StreamTaskTest method testMetrics.
@Test
public void testMetrics() {
task = createStatelessTask(createConfig("100"));
assertNotNull(getMetric("enforced-processing", "%s-rate", task.id().toString()));
assertNotNull(getMetric("enforced-processing", "%s-total", task.id().toString()));
assertNotNull(getMetric("record-lateness", "%s-avg", task.id().toString()));
assertNotNull(getMetric("record-lateness", "%s-max", task.id().toString()));
assertNotNull(getMetric("active-process", "%s-ratio", task.id().toString()));
assertNotNull(getMetric("active-buffer", "%s-count", task.id().toString()));
testMetricsForBuiltInMetricsVersionLatest();
final JmxReporter reporter = new JmxReporter();
final MetricsContext metricsContext = new KafkaMetricsContext("kafka.streams");
reporter.contextChange(metricsContext);
metrics.addReporter(reporter);
final String threadIdTag = THREAD_ID_TAG;
assertTrue(reporter.containsMbean(String.format("kafka.streams:type=stream-task-metrics,%s=%s,task-id=%s", threadIdTag, threadId, task.id())));
}
Aggregations