Search in sources :

Example 16 with MetricConfig

use of org.apache.kafka.common.metrics.MetricConfig in project kafka by apache.

the class SenderTest method setup.

@Before
public void setup() {
    Map<String, String> metricTags = new LinkedHashMap<>();
    metricTags.put("client-id", CLIENT_ID);
    MetricConfig metricConfig = new MetricConfig().tags(metricTags);
    metrics = new Metrics(metricConfig, time);
    accumulator = new RecordAccumulator(batchSize, 1024 * 1024, CompressionType.NONE, 0L, 0L, metrics, time);
    sender = new Sender(client, metadata, this.accumulator, true, MAX_REQUEST_SIZE, ACKS_ALL, MAX_RETRIES, metrics, time, REQUEST_TIMEOUT);
    metadata.update(cluster, Collections.<String>emptySet(), time.milliseconds());
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) Metrics(org.apache.kafka.common.metrics.Metrics) LinkedHashMap(java.util.LinkedHashMap) Before(org.junit.Before)

Example 17 with MetricConfig

use of org.apache.kafka.common.metrics.MetricConfig in project apache-kafka-on-k8s by banzaicloud.

the class KafkaAdminClient method createInternal.

static KafkaAdminClient createInternal(AdminClientConfig config, KafkaClient client, Metadata metadata, Time time) {
    Metrics metrics = null;
    String clientId = generateClientId(config);
    try {
        metrics = new Metrics(new MetricConfig(), new LinkedList<MetricsReporter>(), time);
        return new KafkaAdminClient(config, clientId, time, metadata, metrics, client, null, createLogContext(clientId));
    } catch (Throwable exc) {
        closeQuietly(metrics, "Metrics");
        throw new KafkaException("Failed create new KafkaAdminClient", exc);
    }
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) Metrics(org.apache.kafka.common.metrics.Metrics) KafkaException(org.apache.kafka.common.KafkaException) LinkedList(java.util.LinkedList)

Example 18 with MetricConfig

use of org.apache.kafka.common.metrics.MetricConfig in project apache-kafka-on-k8s by banzaicloud.

the class KafkaAdminClient method createInternal.

static KafkaAdminClient createInternal(AdminClientConfig config, TimeoutProcessorFactory timeoutProcessorFactory) {
    Metrics metrics = null;
    NetworkClient networkClient = null;
    Time time = Time.SYSTEM;
    String clientId = generateClientId(config);
    ChannelBuilder channelBuilder = null;
    Selector selector = null;
    ApiVersions apiVersions = new ApiVersions();
    LogContext logContext = createLogContext(clientId);
    try {
        // Since we only request node information, it's safe to pass true for allowAutoTopicCreation (and it
        // simplifies communication with older brokers)
        Metadata metadata = new Metadata(config.getLong(AdminClientConfig.RETRY_BACKOFF_MS_CONFIG), config.getLong(AdminClientConfig.METADATA_MAX_AGE_CONFIG), true);
        List<MetricsReporter> reporters = config.getConfiguredInstances(AdminClientConfig.METRIC_REPORTER_CLASSES_CONFIG, MetricsReporter.class);
        Map<String, String> metricTags = Collections.singletonMap("client-id", clientId);
        MetricConfig metricConfig = new MetricConfig().samples(config.getInt(AdminClientConfig.METRICS_NUM_SAMPLES_CONFIG)).timeWindow(config.getLong(AdminClientConfig.METRICS_SAMPLE_WINDOW_MS_CONFIG), TimeUnit.MILLISECONDS).recordLevel(Sensor.RecordingLevel.forName(config.getString(AdminClientConfig.METRICS_RECORDING_LEVEL_CONFIG))).tags(metricTags);
        reporters.add(new JmxReporter(JMX_PREFIX));
        metrics = new Metrics(metricConfig, reporters, time);
        String metricGrpPrefix = "admin-client";
        channelBuilder = ClientUtils.createChannelBuilder(config);
        selector = new Selector(config.getLong(AdminClientConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG), metrics, time, metricGrpPrefix, channelBuilder, logContext);
        networkClient = new NetworkClient(selector, metadata, clientId, 1, config.getLong(AdminClientConfig.RECONNECT_BACKOFF_MS_CONFIG), config.getLong(AdminClientConfig.RECONNECT_BACKOFF_MAX_MS_CONFIG), config.getInt(AdminClientConfig.SEND_BUFFER_CONFIG), config.getInt(AdminClientConfig.RECEIVE_BUFFER_CONFIG), (int) TimeUnit.HOURS.toMillis(1), time, true, apiVersions, logContext);
        return new KafkaAdminClient(config, clientId, time, metadata, metrics, networkClient, timeoutProcessorFactory, logContext);
    } catch (Throwable exc) {
        closeQuietly(metrics, "Metrics");
        closeQuietly(networkClient, "NetworkClient");
        closeQuietly(selector, "Selector");
        closeQuietly(channelBuilder, "ChannelBuilder");
        throw new KafkaException("Failed create new KafkaAdminClient", exc);
    }
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) Metadata(org.apache.kafka.clients.Metadata) LogContext(org.apache.kafka.common.utils.LogContext) Time(org.apache.kafka.common.utils.Time) JmxReporter(org.apache.kafka.common.metrics.JmxReporter) Metrics(org.apache.kafka.common.metrics.Metrics) NetworkClient(org.apache.kafka.clients.NetworkClient) MetricsReporter(org.apache.kafka.common.metrics.MetricsReporter) ApiVersions(org.apache.kafka.clients.ApiVersions) KafkaException(org.apache.kafka.common.KafkaException) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) Selector(org.apache.kafka.common.network.Selector)

Example 19 with MetricConfig

use of org.apache.kafka.common.metrics.MetricConfig in project apache-kafka-on-k8s by banzaicloud.

the class ProducerMetrics method main.

public static void main(String[] args) {
    Map<String, String> metricTags = Collections.singletonMap("client-id", "client-id");
    MetricConfig metricConfig = new MetricConfig().tags(metricTags);
    Metrics metrics = new Metrics(metricConfig);
    ProducerMetrics metricsRegistry = new ProducerMetrics(metrics);
    System.out.println(Metrics.toHtmlTable("kafka.producer", metricsRegistry.getAllTemplates()));
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) Metrics(org.apache.kafka.common.metrics.Metrics)

Example 20 with MetricConfig

use of org.apache.kafka.common.metrics.MetricConfig in project apache-kafka-on-k8s by banzaicloud.

the class SenderTest method setupWithTransactionState.

private void setupWithTransactionState(TransactionManager transactionManager) {
    Map<String, String> metricTags = new LinkedHashMap<>();
    metricTags.put("client-id", CLIENT_ID);
    MetricConfig metricConfig = new MetricConfig().tags(metricTags);
    this.metrics = new Metrics(metricConfig, time);
    this.accumulator = new RecordAccumulator(logContext, batchSize, 1024 * 1024, CompressionType.NONE, 0L, 0L, metrics, time, apiVersions, transactionManager);
    this.senderMetricsRegistry = new SenderMetricsRegistry(this.metrics);
    this.sender = new Sender(logContext, this.client, this.metadata, this.accumulator, false, MAX_REQUEST_SIZE, ACKS_ALL, Integer.MAX_VALUE, this.senderMetricsRegistry, this.time, REQUEST_TIMEOUT, 50, transactionManager, apiVersions);
    this.metadata.update(this.cluster, Collections.<String>emptySet(), time.milliseconds());
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) Metrics(org.apache.kafka.common.metrics.Metrics) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

MetricConfig (org.apache.kafka.common.metrics.MetricConfig)44 Metrics (org.apache.kafka.common.metrics.Metrics)32 MetricName (org.apache.kafka.common.MetricName)23 Test (org.junit.Test)14 KafkaMetric (org.apache.kafka.common.metrics.KafkaMetric)8 Sensor (org.apache.kafka.common.metrics.Sensor)8 MockTime (org.apache.kafka.common.utils.MockTime)8 HashSet (java.util.HashSet)7 LinkedHashMap (java.util.LinkedHashMap)7 MetricNameTemplate (org.apache.kafka.common.MetricNameTemplate)7 JmxReporter (org.apache.kafka.common.metrics.JmxReporter)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 KafkaException (org.apache.kafka.common.KafkaException)6 Collections (java.util.Collections)5 Map (java.util.Map)5 TimeUnit (java.util.concurrent.TimeUnit)5 Metric (org.apache.kafka.common.Metric)5 TopicPartition (org.apache.kafka.common.TopicPartition)5