Search in sources :

Example 1 with CustomMetricUpdateListener

use of com.ibm.streamsx.kafka.clients.metrics.CustomMetricUpdateListener in project streamsx.kafka by IBMStreams.

the class AbstractKafkaProducerClient method createProducer.

protected final synchronized void createProducer() {
    final String applicationDirectory = getOperatorContext().getPE().getApplicationDirectory().getAbsolutePath();
    SystemProperties.resolveApplicationDir(applicationDirectory);
    producer = new KafkaProducer<>(this.kafkaProperties);
    producerGenerationMetric.increment();
    if (metricsFetcher == null) {
        metricsFetcher = new MetricsFetcher(getOperatorContext(), new MetricsProvider() {

            @Override
            public Map<MetricName, ? extends Metric> getMetrics() {
                synchronized (AbstractKafkaProducerClient.this) {
                    return producer.metrics();
                }
            }

            @Override
            public String createCustomMetricName(MetricName metricName) throws KafkaMetricException {
                return ProducerMetricsReporter.createOperatorMetricName(metricName);
            }
        }, ProducerMetricsReporter.getMetricsFilter(), AbstractKafkaClient.METRICS_REPORT_INTERVAL);
        metricsFetcher.registerUpdateListener(this.metricsMonitor);
        metricsFetcher.registerUpdateListener("record-queue-time-max", new CustomMetricUpdateListener() {

            @Override
            public void customMetricUpdated(final String customMetricName, final MetricName kafkaMetricName, final long value) {
                metricsMonitor.setRecordQueueTimeMax(value);
                recordQueueTimeMaxMName.compareAndSet(null, kafkaMetricName);
            }
        });
        metricsFetcher.registerUpdateListener("outgoing-byte-rate", new CustomMetricUpdateListener() {

            @Override
            public void customMetricUpdated(final String customMetricName, final MetricName kafkaMetricName, final long value) {
                metricsMonitor.setOutgoingByteRate(value);
                outGoingByteRateMName.compareAndSet(null, kafkaMetricName);
            }
        });
        metricsFetcher.registerUpdateListener("records-per-request-avg", new CustomMetricUpdateListener() {

            @Override
            public void customMetricUpdated(final String customMetricName, final MetricName kafkaMetricName, final long value) {
                metricsMonitor.setRecordsPerRequestAvg(value);
            }
        });
        metricsFetcher.registerUpdateListener("batch-size-avg", new CustomMetricUpdateListener() {

            @Override
            public void customMetricUpdated(final String customMetricName, final MetricName kafkaMetricName, final long value) {
                metricsMonitor.setBatchSizeAvg(value);
            }
        });
        metricsFetcher.registerUpdateListener("buffer-available-bytes", new CustomMetricUpdateListener() {

            @Override
            public void customMetricUpdated(final String customMetricName, final MetricName kafkaMetricName, final long value) {
                metricsMonitor.setBufferAvailBytes(value);
                bufferAvailMName.compareAndSet(null, kafkaMetricName);
            }
        });
        metricsFetcher.registerUpdateListener("record-queue-time-avg", new CustomMetricUpdateListener() {

            @Override
            public void customMetricUpdated(final String customMetricName, final MetricName kafkaMetricName, final long value) {
                metricsMonitor.setRecordQueueTimeAvg(value);
            }
        });
        metricsFetcher.registerUpdateListener("bufferpool-wait-time-total", new CustomMetricUpdateListener() {

            @Override
            public void customMetricUpdated(final String customMetricName, final MetricName kafkaMetricName, final long value) {
                metricsMonitor.setBufferPoolWaitTimeTotalNanos(value);
            }
        });
        metricsFetcher.registerUpdateListener("request-rate", new CustomMetricUpdateListener() {

            @Override
            public void customMetricUpdated(final String customMetricName, final MetricName kafkaMetricName, final long value) {
                metricsMonitor.setRequestRate(value);
            }
        });
    }
}
Also used : MetricName(org.apache.kafka.common.MetricName) MetricsFetcher(com.ibm.streamsx.kafka.clients.metrics.MetricsFetcher) MetricsProvider(com.ibm.streamsx.kafka.clients.metrics.MetricsProvider) CustomMetricUpdateListener(com.ibm.streamsx.kafka.clients.metrics.CustomMetricUpdateListener)

Aggregations

CustomMetricUpdateListener (com.ibm.streamsx.kafka.clients.metrics.CustomMetricUpdateListener)1 MetricsFetcher (com.ibm.streamsx.kafka.clients.metrics.MetricsFetcher)1 MetricsProvider (com.ibm.streamsx.kafka.clients.metrics.MetricsProvider)1 MetricName (org.apache.kafka.common.MetricName)1