Metrics API - GET metrics

Lists all available metrics.

You can limit the output by using the pagination:

  1. Specify the number of results per page in the pageSize query parameter.
  2. Then use the cursor from the nextPageKey field of the previous response in the nextPageKey query parameter to obtain subsequent pages.

The request produces one of the following types of payload, depending on the value of the the Accept request header:

  • application/json
  • text/csv; header=present—a CSV table with header row
  • text/csv; header=absent—a CSV table without header row

If no Accept header is provided with the request, an application/json payload is returned.

GET
  • Managed https://{your-domain}/e/{your-environment-id}/api/v2/metrics
  • SaaS https://{your-environment-id}.live.dynatrace.com/api/v2/metrics

Authentication

To execute this request, you need the Read metrics (metrics.read) permission assigned to your API token. To learn how to obtain and use it, see Tokens and authentication.

Parameters

Parameter Type Description In Required
nextPageKey string

The cursor for the next page of results. You can find it in the nextPageKey field of the previous response.

The first page is always returned if you don't specify the nextPageKey query parameter.

When the nextPageKey is set to obtain subsequent pages, you must omit all other query parameters.

query optional
pageSize integer

The amount of primary entities in a single response payload.

The maximal allowed page size is 500.

If not set, 100 is used.

If a value higher than 500 is used, only 500 results per page are returned.

query optional
metricSelector string

Selects metrics for the query by their keys.

You can specify multiple metric keys separated by commas (for example, metrickey1,metrickey2). To select multiple metrics belonging to the same parent, list the last part of the required metric keys in parentheses, separated by commas, while keeping the common part untouched. For example, to list the builtin:host.cpu.idle and builtin:host.cpu.user metric, write: builtin:host.cpu.(idle,user).

You can select a full set of related metrics by using a trailing asterisk (*) wildcard. For example, builtin:host.* selects all host-based metrics and builtin:* selects all Dynatrace-provided metrics.

You can set additional transformation operators, separated by a colon (:). See the Metrics selector transformations help page for additional information on available result transformations.

Only aggregation, merge, parents, and splitBy transformations are supported by this endpoint.

The length of the string is limited to 2,000 characters.

To find metrics based on a search term, rather than metricId, use the text query parameter instead of this one.

query optional
text string

Metric registry search term. Only show metrics that contain the term in their key, display name, or description. Use the metricSelector parameter instead of this one to select a complete metric hierarchy instead of doing a text-based search.

query optional
fields string

Defines the list of metric properties included in the response.

metricId is always included in the result. The following additional properties are available:

  • displayName: The name of the metric in the user interface. Enabled by default.
  • description: A short description of the metric. Enabled by default.
  • unit: The unit of the metric. Enabled by default.
  • tags: The tags of the metric.
  • dduBillable: An indicator whether the usage of metric consumes Davis data units.
  • created: The timestamp (UTC milliseconds) when the metrics has been created.
  • lastWritten: The timestamp (UTC milliseconds) when metric data points have been written for the last time.
  • aggregationTypes: The list of allowed aggregations for the metric. Note that it may be different after a transformation is applied.
  • defaultAggregation: The default aggregation of the metric. It is used when no aggregation is specified or the :auto transformation is set.
  • dimensionDefinitions: The fine metric division (for example, process group and process ID for some process-related metric).
  • transformations: A list of transformations that can be applied to the metric.
  • entityType: A list of entity types supported by the metric.

To add properties, list them with leading plus +. To exclude default properties, list them with leading minus -.

To specify several properties, join them with a comma (for example fields=+aggregationTypes,-description).

If you specify just one property, the response contains the metric key and the specified property. To return metric keys only, specify metricId here.

query optional
writtenSince string

Filters the resulted set of metrics to those that have data points within the specified timeframe.

You can use one of the following formats:

  • Timestamp in UTC milliseconds.
  • Human-readable format of 2021-01-25T05:57:01.123+01:00. If no time zone is specified, UTC is used. You can use a space character instead of the T. Seconds and fractions of a second are optional.
  • Relative timeframe, back from now. The format is now-NU/A, where N is the amount of time, U is the unit of time, and A is an alignment. The alignment rounds all the smaller values to the nearest zero in the past. For example, now-1y/w is one year back, aligned by a week. You can also specify relative timeframe without an alignment: now-NU. Supported time units for the relative timeframe are:
    • m: minutes
    • h: hours
    • d: days
    • w: weeks
    • M: months
    • y: years
query optional
metadataSelector string

The metadata scope of the query. Only metrics with specified properties are included to the response.

You can set one or more of the following criteria. Values are case-sensitive and the EQUALS operator is used. If several values are specified, the OR logic applies.

  • unit("unit-1","unit-2")
  • tags("tag-1","tag-2")

To set several criteria, separate them with a comma (,). For example, tags("feature","cloud"),unit("Percent"). Only results matching all criteria are included in response.

For example, to list metrics that have the tags feature AND cloud with a unit of Percent OR MegaByte, use this metadataSelector: tags("feature"),unit("Percent","MegaByte"),tags("cloud").

query optional

Response

Response codes

Code Description
200

Success

400

Syntax or validation error. metricSelector or fields have syntactic or semantic errors.

404

Not found. The requested resource is not found or the query is incorrect.

406

Not acceptable. The requested media type is not supported. Check the Accept header of your request.

Response body

The MetricDescriptorCollection object

A list of metrics along with their descriptors.

Element Type Description
totalCount integer

The estimated number of metrics in the result.

nextPageKey string

The cursor for the next page of results. Has the value of null on the last page.

Use it in the nextPageKey query parameter to obtain subsequent pages of the result.

warnings string[]

A list of potential warnings about the query. For example deprecated feature usage etc.

metrics MetricDescriptor[]

A list of metric along with their descriptors

The MetricDescriptor object

The descriptor of a metric.

Element Type Description
tags string[]

The tags applied to the metric

entityType string[]

List of admissible primary entity types for this metric. Can be used for the type predicate in the entitySelector.

metricId string

The fully qualified key of the metric.

If a transformation has been used it is reflected in the metric key.

aggregationTypes string[]

The list of allowed aggregations for this metric.

metricValueType MetricValueType
lastWritten integer

The timestamp when the metric was last written.

Has the value of null if the data has never been written.

impactRelevant boolean

The metric is (true) or is not (false) impact relevant.

dimensionDefinitions MetricDimensionDefinition[]

The fine metric division (for example, process group and process ID for some process-related metric).

rootCauseRelevant boolean

The metric is (true) or is not (false) root cause relevant.

maximumValue number

The maximum value of the metric.

minimumValue number

The minimum value of the metric.

dduBillable boolean

If true the usage of metric consumes Davis data units.

defaultAggregation MetricDefaultAggregation
warnings string[]

A list of potential warnings that affect this ID. For example deprecated feature usage etc.

description string

A short description of the metric.

transformations string[]

Transform operators that could be appended to the current transformation list. Must be enabled with the "fields" parameter on /metrics and is always present on /metrics/{metricId}.

unit string

The unit of the metric.

created integer

The timestamp of metric creation.

Built-in metrics have the value of null.

displayName string

The name of the metric in the user interface.

The MetricDefaultAggregation object

The default aggregation of a metric.

Element Type Description
parameter number

The percentile to be delivered. Valid values are between 0 and 100.

Applicable only to the percentile aggregation type.

type string

The type of default aggregation.

The MetricDimensionDefinition object

The dimension of a metric.

Element Type Description
index integer

The unique 0-based index of the dimension.

Appending transformations such as :names or :parents may change the indexes of dimensions. null is used for the dimensions of a metric with flexible dimensions, which can be referenced with their dimension key, but do not have an intrinsic order that could be used for the index.

name string

The name of the dimension.

key string

The key of the dimension.

It must be unique within the metric.

type string

The type of the dimension.

displayName string

The display name of the dimension.

The MetricValueType object

The value type for the metric.

Element Type Description
type string

The metric value type

Example

In this example, the request queries all built-in metrics (metricSelector is set to builtin:*) available in the mySampleEnv environment. The following fields are included in the response:

  • metricId
  • unit
  • aggregationTypes

To achieve that, the fields query parameter is set to unit,aggregationTypes.

The API token is passed in the Authorization header.

The response is in application/json format and is truncated to four entries.

Curl

curl -L -X GET 'https://mySampleEnv.live.dynatrace.com/api/v2/metrics?fields=unit,aggregationTypes&metricSelector=builtin:*' \
-H 'Authorization: Api-Token abcdefjhij1234567890' \
-H 'Accept: application/json'

Request URL

https://mySampleEnv.live.dynatrace.com/api/v2/metrics?fields=unit,aggregationTypes&metricSelector=builtin:*

Response body

{
  "totalCount": 1808,
  "nextPageKey": "___a7acX3q0AAAAGAQAJYnVpbHRpbjoqAQA",
  "metrics": [
    {
      "metricId": "builtin:host.cpu.idle",
      "unit": "Percent",
      "aggregationTypes": [
        "auto",
        "avg",
        "max",
        "min"
      ]
    },
    {
      "metricId": "builtin:host.cpu.load",
      "unit": "Ratio",
      "aggregationTypes": [
        "auto",
        "avg",
        "max",
        "min"
      ]
    },
    {
      "metricId": "builtin:service.errors.server.count",
      "unit": "Count",
      "aggregationTypes": [
        "auto",
        "value"
      ]
    },
    {
      "metricId": "builtin:service.keyRequest.count.client",
      "unit": "Count",
      "aggregationTypes": [
        "auto",
        "value"
      ]
    }
  ]
}

The CSV table with header row looks like this. To obtain it, change the Accept header to text/csv; header=present.

metricId,unit,aggregationTypes
builtin:host.cpu.idle,Percent,"[auto, avg, max, min]"
builtin:host.cpu.load,Ratio,"[auto, avg, max, min]"
builtin:service.errors.server.count,Count,"[auto, value]"
builtin:service.keyRequest.count.client,Count,"[auto, value]"

Response code

200