Using operator metrics
The Python Operator API provides runtime access to metrics similar to the access C++
APIs provide. Operator metrics are accessed through the
streams.OperatorMetrics
interface by obtaining a reference using
OperatorContext.getMetrics()
.
For detailed information about Operator metrics, see the doxygen documentation.
OperatorMetrics
provides access to the system operator metrics
using OperatorMetrics.InputPortMetricName
and
OperatorMetrics.OutputPortMetricName
enumerations for metric names
and OperatorMetrics.getInputPortMetric
and
OperatorMetrics.getOutputPortMetric
.
Custom metrics can be created and fetched (including metrics that are defined by the
operator model) using OperatorMetrics.createCustomMetric()
and
OperatorMetrics.getCustomMetric()
. PE-level system metrics are
similarly obtained through the streams.PEMetrics
interface by obtaining
a reference using OperatorContext.getPE().getMetrics()
.
All metrics are represented as a streams.Metric
instance, with the
mapping of the SPL int64
type to a Python int
. 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.
Creating a metric
opMetrics = self.getContext().getMetrics()
discardsMetric = opMetrics.createCustomMetric("nDiscardedTuples",
"Number of discarded tuples", streams.Metric.Kind.COUNTER);
Usage:
if (discardTuple)
discardsMetric.incrementValue(1)
else
self.submitTuple(tuple, port)