IBM Streams 4.2

Using operator metrics

The Java™ Operator API provides runtime access to metrics similar to the access C++ APIs provide. Operator metrics are accessed through the com.ibm.streams.operator.metrics.OperatorMetrics interface by obtaining a reference using OperatorContext.getMetrics().

For detailed information about Operator metrics, see Metrics access. OperatorMetrics provides access to the system operator metrics using OperatorMetrics.InputPortMetric and OperatorMetrics.OutputPortMetric enumerations for metric names.

Custom metrics can be created and fetched (including metrics that are defined by the operator model) using createCustomMetric() and getCustomMetric(). PE-level system metrics are similarly obtained through the com.ibm.streams.operator.metrics.PEMetrics interface by obtaining a reference using OperatorContext.getPE().getMetrics().

All metrics are represented as a com.ibm.streams.operator.metrics.Metric instance, with the mapping of the SPL int64 type to a Java primitive long. The enumeration Metric.Kind indicates the kind of the metric (COUNTER, GAUGE, TIME) solely as an indication to external monitoring tools as to what the metric represents and how to display its value. A metric's kind has no impact on its function.

An example of creating a metric is shown.

OperatorMetrics opMetrics = getOperatorContext().getMetrics();
		
Metric discards = opMetrics.createCustomMetric("nDiscardedTuples",
				"Number of discarded tuples", Metric.Kind.COUNTER);

Usage:

if (discardTuple)
  discards.incrementValue(1);
else
  port.submit(tuple);