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