Homeโ€บ๐Ÿ“ก SNMP Extensionsโ€บModule 71 min read ยท 8/16

Calculated Metrics (func:)

Hands-on2 exercises

What Are func: Metrics?

Calculated metrics let you compute values server-side without writing code. Prefix the key with func::

- key: func:my_ext.uptime_hours
  query:
    metricSelector: (my_ext.sysuptime:splitBy("dt.entity.my_ext:device") / 360000)
  metadata:
    displayName: Uptime (Hours)
    unit: Hour

โš ๏ธ func: metrics only work in screens and dashboards. They're NOT stored in Grail โ€” you can't query them with DQL.

Common Patterns

CalculationFormulaUnit
Uptime in hours(sysuptime:splitBy(...) / 360000)Hour
Memory %(used:splitBy(...) / (used + free):splitBy(...) * 100)Percent
Bandwidth %((bytes.count:splitBy(...) * 8):rate(1s) / (speed * 1000000) * 100)Percent
Error rate(errors.count:splitBy(...):rate(1m))Count

๐Ÿ’ก The :splitBy() is required โ€” it tells the Metrics API which dimensions to group by. Always include the entity dimension.

๐Ÿ›  Try it

Create a func: metric that converts sysUpTime (hundredths of seconds) to hours. Divide by 360000 and use :splitBy("dt.entity.calc_lab:device").

extension.yamlYAML
Loading...

Using func: in Screens

Reference them in charts just like regular metrics:

charts:
  - displayName: Uptime
    visualizationType: SINGLE_VALUE
    singleValueConfig:
      metric:
        metricSelector: func:my_ext.uptime_hours:splitBy("dt.entity.my_ext:device")

func: Metrics in Alerts

Since func: metrics aren't stored in Grail, alerts must use METRIC_SELECTOR query type:

query_definition {
  type            = "METRIC_SELECTOR"
  metric_selector = "func:my_ext.uptime_hours:splitBy()"
}

โš ๏ธ Using METRIC_KEY with a func: metric silently fails โ€” the alert never fires. This is a common production bug.

๐Ÿ›  Try itExercise 2

Create a memory usage percentage metric from mem_used and mem_free. Formula: used / (used + free) * 100.

extension.yamlYAML
Loading...

What's Next

Module 8 โ€” Build, sign, and deploy your extension to Dynatrace.