Create a metric

Define a set of time based metrics that are generated using captured and stored streamed events


Metrics are defined as individual units referred to as a metric family. A metric family is an SQL query that defines metric calculations computed within a continuous scheduled cycle, making them available to all processors.

Metrics Definition

This example configures a list of metrics to be computed. One or more metric families can be configured, each there own management policies.

Example

foreach metric compute:
  metrics:
    - name: BidMovingAverage
      metric key: symbol
      table definition: standardQuoteAnalyticsStream.BidMovingAverage (symbol VARCHAR, avg_bid_min FLOAT, avg_bid_avg FLOAT,avg_bid_max FLOAT)
      query:
        SELECT symbol,
          MIN(bid) AS 'avg_bid_min',
          AVG(bid) AS 'avg_bid_avg',
          MAX(bid) AS 'avg_bid_max'
        FROM standardQuoteAnalyticsStream.quote
        WHERE
          ingestTime >= date_trunc('minutes',now() - INTERVAL 2 MINUTES) AND ingestTime <= date_trunc('minutes',now())
        GROUP BY symbol
        ORDER BY 1;
      truncate on start: true
      compaction policy:
        frequency: 8
        time unit: HOURS

Metric attributes

Each metric is defined using the below metrics.

AttributeDescriptionData TypeRequired

name

Unique metric family name

String

metric key

Unique key for the metric to be used to optimise query generation and processing

String

query

Metrics ANSI SQL query, See DuckDB SQL documentation

String

table definition

SQL table definition for the resulting metrics

String

truncate on start

Truncate metric data on restart. Note if you import metrics using the initialisation DSL element you will need to set this to false.

Boolean Default: true

compaction policy

Compact the table

Compaction policy

Compacts the metric table by deleting all row less than the max createdTimestamp

AttributeDescriptionData TypeRequired

frequency

Frequency to execute compaction processing. Default is set to 1.

Long

time units

Time unit frequency is define as. Default is set to HOURS. Support unit MINUTES and HOURS

String

compaction query

User defined compaction query

String

Last updated