use of com.ibm.streams.operator.metrics.OperatorMetrics in project streamsx.topology by IBMStreams.
the class Resetter method createConditionMetrics.
private void createConditionMetrics() {
final OperatorMetrics metrics = getOperatorContext().getMetrics();
final String name = getConditionName();
valid = metrics.createCustomMetric(metricName("valid", name), "Condition: " + name + " is valid", Metric.Kind.GAUGE);
seq = metrics.createCustomMetric(metricName("seq", name), "Condition: " + name + " sequence", Metric.Kind.COUNTER);
fail = metrics.createCustomMetric(metricName("fail", name), "Condition: " + name + " failed", Metric.Kind.GAUGE);
}
use of com.ibm.streams.operator.metrics.OperatorMetrics in project streamsx.kafka by IBMStreams.
the class AbstractKafkaClient method tryCreateCustomMetric.
/**
* Tests existence of a custom metric and creates the metric if it does not yet exist.
* @param name the name of the metric
* @param descr the description
* @param kind the kind of the metric
* @return the Metric object.
*/
protected Metric tryCreateCustomMetric(final String name, final String descr, final Metric.Kind kind) {
OperatorMetrics metrics = getOperatorContext().getMetrics();
Metric m = metrics.getCustomMetrics().get(name.trim());
if (m != null)
return m;
return metrics.createCustomMetric(name, descr, kind);
}
use of com.ibm.streams.operator.metrics.OperatorMetrics in project streamsx.kafka by IBMStreams.
the class AbstractCustomMetricReporter method metricRemoval.
/**
* This is called whenever a metric is removed.
* It sets the value of the corresponding operator metric,
* if there is one, to {@value #METRIC_NOT_APPLICABLE} as custom metrics cannot be deleted from operators.
*
* @param metric The metric that is removed from Kafka
*/
@Override
public void metricRemoval(KafkaMetric metric) {
trace.log(DEBUG_LEVEL, "metricRemoval(): " + metric.metricName());
synchronized (this) {
if (getFilter().apply(metric)) {
final MetricName metricName = metric.metricName();
try {
final String customMetricName = createCustomMetricName(metricName);
OperatorMetrics operatorMetrics = operatorCtx.getMetrics();
if (operatorMetrics.getCustomMetrics().containsKey(customMetricName)) {
operatorMetrics.getCustomMetric(customMetricName).setValue(METRIC_NOT_APPLICABLE);
}
} catch (KafkaMetricException e) {
trace.warn("Cannot derive custom metric from Kafka metric '" + metricName + "': " + e.getLocalizedMessage());
}
} else {
trace.log(DEBUG_LEVEL, "Kafka metric NOT exposed as custom metric: " + metric.metricName());
}
}
}
use of com.ibm.streams.operator.metrics.OperatorMetrics 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