Apply metrics

Apply metrics within stream processing functions

Objective

Use calculated metrics within processor logic, analytics, ML inferencing or simply send metrics to connected consumers.

Metrics applications

To access metrics two methods have been provided:

  • Emit projection Metrics can be included within the emit select statement to enhance output events.

  • Query interface Metrics can also be accessed via the Metric Query API for use in custom processors, enhancing the integration of metric data in analytics workflows.

Emit projection

Metrics can be added to the final output event using the emit select statement metrics query syntax.

This section explains how use the metrics query language.

Example

This example will add the avg_bid_max metric to the output event on a successful symbol look up match.

emit:
  select: "symbol, BidMovingAverage.avg_bid_max; WHERE symbol=${symbol} 'avg_bid_max'"

Query Structure

Users define metric queries directly within the select statement, allowing for dynamic lookups based on conditions such as a symbol value.

The query structure is formed of three required components and an optional override output alias.

Required components:

  • metric-family

  • metrics

  • predicate

Optional

  • output-alias

Structure follows a pragmatic form:

<metrics-family>.<metrics>;<predicate> '<output-alias>'

metric-family

This is the logical name of the group of metrics, which should correspond to a metric name declared within the compute section.

metrics

A comma delimited list of metrics or asterisk. Any defined metric needs to correspond the query projection attributes.

predicate

Matching and filtering statement using standard SQL. This is used to extract only those records that fulfils a specified condition.

-- Simple lookup
WHERE symbol='IBM'

-- Parameter replace using the corresponding the event object symbol value
WHERE symbol=${symbol}

-- Apply additonal filtering criteria
WHERE symbol=${symbol} AND avg_bid_max > 120.88

output alias

Use an alias for the output metric rather than the metric name for a single field output.

Examples

-- Get all metrics from the BidMovingAverage metrics family for IBM 
BidMovingAverage.*;WHERE symbol='IBM'

-- Get the avg_bid_max metric from the BidMovingAverage metrics family all symbols matching the reference ${symbol} variable 
BidMovingAverage.avg_bid_max;WHERE symbol=${symbol}

-- Same as above with the ability to define a custom name for the resulting field
BidMovingAverage.avg_bid_max;WHERE symbol=${symbol} 'avg_bid_max'

-- Get the avg_bid_max and avg_bid_min metric from the BidMovingAverage metrics family
BidMovingAverage.avg_bid_max,avg_bid_min;WHERE symbol=${symbol}

Query interface

Metrics can also be accessed via the Metric Query API for use in custom processors, enhancing the integration of metric data in analytics workflows.

Find further information on how to leverage the value through the API documentation

Last updated