Search in sources :

Example 6 with KafkaMetricException

use of com.ibm.streamsx.kafka.KafkaMetricException in project streamsx.kafka by IBMStreams.

the class AbstractCustomMetricReporter method tryCreateCustomMetric.

/**
 * creates a custom metric if it is not yet present.
 * The custom metric name is created using {@link #createCustomMetricName(MetricName)}.
 * @param metric The name of the Kafka metric
 */
private void tryCreateCustomMetric(final Metric metric) {
    final MetricName metricName = metric.metricName();
    try {
        final String customMetricName = createCustomMetricName(metricName);
        OperatorMetrics operatorMetrics = operatorCtx.getMetrics();
        if (operatorMetrics.getCustomMetrics().containsKey(customMetricName)) {
            trace.info("Custom metric already created: " + customMetricName);
            operatorMetrics.getCustomMetric(customMetricName).setValue(getFilter().getConverter(metric).convert(metric.metricValue()));
            return;
        }
        operatorMetrics.createCustomMetric(customMetricName, metricName.description(), com.ibm.streams.operator.metrics.Metric.Kind.GAUGE);
        operatorMetrics.getCustomMetric(customMetricName).setValue(getFilter().getConverter(metric).convert(metric.metricValue()));
        trace.info("custom metric created: " + customMetricName + " (" + metricName.description() + ")");
    } catch (KafkaMetricException e) {
        trace.warn("Cannot create custom metric from Kafka metric '" + metricName + "': " + e.getLocalizedMessage());
    }
}
Also used : MetricName(org.apache.kafka.common.MetricName) OperatorMetrics(com.ibm.streams.operator.metrics.OperatorMetrics) KafkaMetricException(com.ibm.streamsx.kafka.KafkaMetricException)

Aggregations

KafkaMetricException (com.ibm.streamsx.kafka.KafkaMetricException)6 MetricName (org.apache.kafka.common.MetricName)5 OperatorMetrics (com.ibm.streams.operator.metrics.OperatorMetrics)2 ConsumerCommitFailedException (com.ibm.streamsx.kafka.ConsumerCommitFailedException)1 KafkaClientInitializationException (com.ibm.streamsx.kafka.KafkaClientInitializationException)1 KafkaConfigurationException (com.ibm.streamsx.kafka.KafkaConfigurationException)1 KafkaOperatorRuntimeException (com.ibm.streamsx.kafka.KafkaOperatorRuntimeException)1 UnknownTopicException (com.ibm.streamsx.kafka.UnknownTopicException)1 MetricsFetcher (com.ibm.streamsx.kafka.clients.metrics.MetricsFetcher)1 MetricsProvider (com.ibm.streamsx.kafka.clients.metrics.MetricsProvider)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CommitFailedException (org.apache.kafka.clients.consumer.CommitFailedException)1 KafkaConsumer (org.apache.kafka.clients.consumer.KafkaConsumer)1 Metric (org.apache.kafka.common.Metric)1 RetriableException (org.apache.kafka.common.errors.RetriableException)1 SerializationException (org.apache.kafka.common.errors.SerializationException)1