Calculated Metrics (func:)
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
| Calculation | Formula | Unit |
|---|---|---|
| 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.
Create a func: metric that converts sysUpTime (hundredths of seconds) to hours. Divide by 360000 and use :splitBy("dt.entity.calc_lab:device").
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.
Create a memory usage percentage metric from mem_used and mem_free. Formula: used / (used + free) * 100.
What's Next
Module 8 โ Build, sign, and deploy your extension to Dynatrace.