Metrics in processors

You can find the general metrics definition in Metrics

Submitting Metrics

The simplest way to submit a metric is to call ctx.meter inside handler function, e.g.

async function handleTransfer(event: TransferEvent, ctx: ERC20Context) {
  ctx.meter.Counter('token').add(event.args.value)
}

Metric Naming

A metric name could contain characters, digits or _, any other characters will be converted to _. It will also be truncated to 512 characters.

Labels

Labels is a map of key to string values, the key name follows the same rule as the metric name, and any reserved keywords will be appended with _ .

The simplest way to submit a metric is to call ctx.meter inside handler function, e.g.

async function handleTransfer(event: TransferEvent, ctx: ERC20Context) {
  ctx.meter.Counter('token').add(event.args.value)
}

Our system automatically adds a few reserved labels, including chain, version, contract_name, contract_address, aggregation_minutes, aggregation_days. If users use these labels, an error will be returned and visible on the UI.

You could also add your own custom labels to differentiate the characteristics of the thing that is being measured. For example:

tvl.record(ctx, v, {coin: coinInfo.symbol, bridge: coinInfo.bridge, type: coinInfo.token_type.type})

This submits TVL with symbol being used as a tag.

Assuming there are N symbols, M bridges and K coin types, the total number of series generated could be as large as N * M * K (but won't exceed the total number of points submitted). Read Avoid High Cardinalityfor more details.

Descriptor

Sometimes you want to give the metric more information, or want to share the same counter/gauge in different handle functions, then you can first declare your counter with an optional descriptor.

const tokenCount = Counter.register(
  'token_count', 
  { description: 'token transferred to my wallet',
    unit: 'eth' 
  })

and then use them as

async function handleTransfer(event: TransferEvent, ctx: ERC20Context) {
  tokenCount.add(ctx, event.args.value)
}

Resolution

You can define pre-aggregation rules for the metrics

export const gaugeOptions: MetricOptions = {
  sparse: true,
  aggregationConfig: {
    intervalInMinutes: [60],
    discardOrigin: true,
  }
}

export const vol = Gauge.register("vol", gaugeOptions)

This will generate 2 new metrics vol_count and vol_sum.

  • vol_count represents the count of data pre-aggregated every 60 minutes.

  • vol_sum represents the sum of data pre-aggregated every 60 minutes.

  • The original metric vol will be omitted since discardOrigin is true.

Last updated