The GET metrics endpoint provides you the ability to query multiple metrics, along with partial or even full descriptors of metrics.
This example shows how to fetch the list of all metrics in the environment with essential metadata.
The most important part is the metric key, as it is used to identify the metric. The key itself, however, doesn't provide much information about metric. To learn more about metrics, we can add this crucial information:
To obtain the full list of metrics, you have to set the following query parameters:
500
. The full list of metrics can be lengthy, so we're using the maximum possible value.displayName,unit,aggregationTypes
. This removes all other fields from the payload, only keeping those we're interested in. Note that metricId
is omitted here, because it is always presented in the response.You can get the response in two formats:
application/json
.text/csv; header=present
. If you're not interested in the header row, use text/csv; header=absent
.To authenticate the request, set the Authorization header of the request to Api-token {your-token}
. The token must have the Read metrics (metrics.read
) permission.
Here's the Curl code of the request. Make sure to use the URL of your own environment and a real API token.
curl -L -X GET 'https://mySampleEnv.live.dynatrace.com/api/v2/metrics?fields=displayName,unit,aggregationTypes&pageSize=500' \-H 'Authorization: Api-Token dt0c01.abc123.abcdefjhij1234567890' \-H 'Accept: application/json'
curl -L -X GET 'https://mySampleEnv.live.dynatrace.com/api/v2/metrics?fields=displayName,unit,aggregationTypes&pageSize=500' \-H 'Authorization: Api-Token dt0c01.abc123.abcdefjhij1234567890' \-H 'Accept: text/csv; header=present'
https://mySampleEnv.live.dynatrace.com/api/v2/metrics?fields=displayName,unit,aggregationTypes&pageSize=500
The full list of metrics is too lengthy, so in each case it is truncated to the same 3 entries.
{"totalCount": 1812,"nextPageKey": null,"metrics": [{"metricId": "builtin:apps.other.apdex.osAndVersion","displayName": "Apdex (by os and app version)","unit": "NotApplicable","aggregationTypes": ["auto","value"]},{"metricId": "builtin:apps.other.keyUserActions.requestErrorCount.os","displayName": "Request error count (by os)","unit": "Count","aggregationTypes": ["auto","value"]},{"metricId": "builtin:tech.activemq.CurrentConnectionsCount","displayName": "Current connections count","unit": "Count","aggregationTypes": ["auto","avg","count","max","min","sum"]}]}
metricId,displayName,unit,aggregationTypesbuiltin:apps.other.apdex.osAndVersion,Apdex (by os and app version),NotApplicable,"[auto, value]"builtin:apps.other.keyUserActions.requestErrorCount.os,Request error count (by os),Count,"[auto, value]"builtin:tech.activemq.CurrentConnectionsCount,Current connections count,Count,"[auto, avg, count, max, min, sum]"