Service metrics API - PUT a metric
Updates the specified calculated service metric.
If the calculated service metric with the specified key doesn't exist, a new metric is created.
PUT | SaaS | https://{your-environment-id}.live.dynatrace.com/api/config/v1/calculatedMetrics/service/{metricKey} |
Environment ActiveGate | https://{your-activegate-domain}:9999/e/{your-environment-id}/api/config/v1/calculatedMetrics/service/{metricKey} |
Authentication
To execute this request, you need an access token with WriteConfig
scope.
To learn how to obtain and use it, see Tokens and authentication.
Parameters
Refer to JSON models to find all JSON models that depend on the type of the model.
Parameter | Type | Description | In | Required |
---|---|---|---|---|
metricKey | string | The key of the calculated service metric to be updated. The key of the calculated service metric in the body of the request must match this key. | path | required |
body | Calculated | The JSON body of the request. Contains updated parameters of the calculated service metric. | body | required |
Request body objects
The CalculatedServiceMetric
object
Descriptor of a calculated service metric.
Element | Type | Description | Required |
---|---|---|---|
conditions | Condition[] | The set of conditions for the metric usage. All the specified conditions must be fulfilled to use the metric. | optional |
dimensionDefinition | Dimension | Parameters of a definition of a calculated service metric. | optional |
enabled | boolean | The metric is enabled ( | required |
entityId | string | Restricts the metric usage to the specified service. This field is mutually exclusive with the managementZones field. | optional |
ignoreMutedRequests | boolean | Metric should ( | optional |
managementZones | string[] | Restricts the metric usage to specified management zones. This field is mutually exclusive with the entityId field. | optional |
metadata | Configuration | Metadata useful for debugging | optional |
metricDefinition | Calculated | The definition of a calculated service metric. | required |
name | string | The displayed name of the metric. | required |
tsmMetricKey | string | The key of the calculated service metric. | required |
unit | string | The unit of the metric.
| required |
unitDisplayName | string | The display name of the metric's unit. Only applicable when the unit parameter is set to | optional |
The Condition
object
A condition of a rule usage.
Element | Type | Description | Required |
---|---|---|---|
attribute | string | The attribute to be matched. Note that for a service property attribute you must use the comparison of the
| required |
comparisonInfo | Comparison | Type-specific comparison for attributes. The actual set of fields depends on the type of the comparison. Find the list of actual objects in the description of the type field or see Service metrics API - JSON models. | required |
The ComparisonInfo
object
Type-specific comparison for attributes. The actual set of fields depends on the type of the comparison. Find the list of actual objects in the description of the type field or see Service metrics API - JSON models.
Element | Type | Description | Required |
---|---|---|---|
comparison | string | Operator of the comparision. You can reverse it by setting negate to | required |
negate | boolean | Reverse the comparison operator. For example, it turns equals into does not equal. | required |
type | string | Defines the actual set of fields depending on the value. See one of the following objects:
| required |
value | string | The value to compare to. | optional |
values | - | The values to compare to. | optional |
The AnyValue
object
A schema representing an arbitrary value type.
The DimensionDefinition
object
Parameters of a definition of a calculated service metric.
Element | Type | Description | Required |
---|---|---|---|
dimension | string | The dimension value pattern. You can define custom placeholders in the placeholders field and use them here. | required |
name | string | The name of the dimension. | required |
placeholders | Placeholder[] | The list of custom placeholders to be used in a dimension value pattern. | optional |
topX | integer | The number of top values to be calculated. | required |
topXAggregation | string | The aggregation of the dimension.
| required |
topXDirection | string | How to calculate the topX values.
| required |
The Placeholder
object
The custom placeholder to be used as a naming value pattern.
It enables you to extract a request attribute value or other request attribute and use it in the naming pattern.
Element | Type | Description | Required |
---|---|---|---|
aggregation | string | Which value of the request attribute must be used when it occurs across multiple child requests. Only applicable for the For the
| optional |
attribute | string | The attribute to extract from. You can only use attributes of the string type.
| required |
delimiterOrRegex | string | Depending on the type value:
| optional |
endDelimiter | string | The closing delimiter string to look for. Required if the kind value is | optional |
kind | string | The type of extraction. Defines either usage of regular expression ( When the attribute is
| required |
name | string | The name of the placeholder. Use it in the naming pattern as | required |
normalization | string | The format of the extracted string.
| optional |
requestAttribute | string | The request attribute to extract from. Required if the kind value is | optional |
source | Propagation | Defines valid sources of request attributes for conditions or placeholders. | optional |
useFromChildCalls | boolean | If Only applicable for the | optional |
The PropagationSource
object
Defines valid sources of request attributes for conditions or placeholders.
Element | Type | Description | Required |
---|---|---|---|
managementZone | string | Use only request attributes from services that belong to this management zone.. Use either this or | optional |
serviceTag | Universal | Use only request attributes from services that have this tag. Use either this or | optional |
The UniversalTag
object
Use only request attributes from services that have this tag. Use either this or managementZone
Element | Type | Description | Required |
---|---|---|---|
context | string | The origin of the tag, such as AWS or Cloud Foundry. For custom tags use the The context is set for tags that are automatically imported by OneAgent (for example, from the AWS console or environment variables). It’s useful for determining the origin of tags when not manually defined, and it also helps to prevent clashes with other existing tags. If the tag is not automatically imported,
| optional |
key | string | The key of the tag. For custom tags, put the tag value here. The key allows categorization of multiple tags. It is possible that there are multiple values for a single key which will all be represented as standalone tags. Therefore, the key does not have the semantic of a map key but is more like a key of a key-value tuple. In some cases, for example custom tags, the key represents the actual tag value and the value field is not set – those are called valueless tags. | required |
tagKey | Universal | - | optional |
value | string | The value of the tag. Not applicable to custom tags. If a tag does have a separate key and value (in the textual representation they are split by the colon ‘:’), this field is set with the actual value. Key-value pairs can occur for automatically imported tags and tags set by rules if extractors are used. | optional |
The UniversalTagKey
object
Element | Type | Description | Required |
---|---|---|---|
context | string | -
| optional |
key | string | - | optional |
The ConfigurationMetadata
object
Metadata useful for debugging
Element | Type | Description | Required |
---|---|---|---|
clusterVersion | string | Dynatrace version. | optional |
configurationVersions | integer[] | A sorted list of the version numbers of the configuration. | optional |
currentConfigurationVersions | string[] | A sorted list of version numbers of the configuration. | optional |
The CalculatedMetricDefinition
object
The definition of a calculated service metric.
Element | Type | Description | Required |
---|---|---|---|
metric | string | The metric to be captured.
| required |
requestAttribute | string | The request attribute to be captured. Only applicable when the metric parameter is set to | optional |
Request body JSON model
This is a model of the request body, showing the possible elements. It has to be adjusted for usage in an actual request.
{"conditions": [{"attribute": "WEBREQUEST_URL_PATH","comparisonInfo": {"caseSensitive": false,"comparison": "BEGINS_WITH","negate": false,"type": "STRING","value": "/url_path"}}],"dimensionDefinition": {"dimension": "{myPlaceholder}","name": "my dimension","placeholders": [{"attribute": "WEBREQUEST_URL_PATH","delimiterOrRegex": "/booking","kind": "BEFORE_DELIMITER","name": "myPlaceholder","normalization": "ORIGINAL","useFromChildCalls": "false"}],"topX": 10,"topXAggregation": "AVERAGE","topXDirection": "DESCENDING"},"enabled": true,"managementZones": ["zone1"],"metricDefinition": {"metric": "CPU_TIME"},"name": "My Metric","tsmMetricKey": "calc:service.mymetric","unit": "MICRO_SECOND"}
Response
Response codes
Code | Type | Description |
---|---|---|
201 | Entity | Success. The new calculated service metric has been created. Response contains the key of the new metric. |
204 | - | Success. The calculated service metric has been updated. Response doesn't have a body. |
400 | Error | Failed. The input is invalid |
Response body objects
The EntityShortRepresentation
object
The short representation of a Dynatrace entity.
Element | Type | Description |
---|---|---|
description | string | A short description of the Dynatrace entity. |
id | string | The ID of the Dynatrace entity. |
name | string | The name of the Dynatrace entity. |
Response body JSON model
{"description": "Dynatrace entity for the REST API example","id": "6a98d7bc-abb9-44f8-ae6a-73e68e71812a","name": "Dynatrace entity"}
Validate payload
We recommend that you validate the payload before submitting it with an actual request. A response code of 204 indicates a valid payload.
The request consumes an application/json
payload.
POST | SaaS | https://{your-environment-id}.live.dynatrace.com/api/config/v1/calculatedMetrics/service/{metricKey}/validator |
Environment ActiveGate | https://{your-activegate-domain}:9999/e/{your-environment-id}/api/config/v1/calculatedMetrics/service/{metricKey}/validator |
Authentication
To execute this request, you need an access token with WriteConfig
scope.
To learn how to obtain and use it, see Tokens and authentication.
Response
Response codes
Code | Type | Description |
---|---|---|
204 | - | Validated. The submitted configuration is valid. Response doesn't have a body. |
400 | Error | Failed. The input is invalid |
Example
In this example, the request modifies the Requests by code calculated service metric created in the POST request example. The request restricts the metric to the Easytravel management zone and adds the condition of process group having the cardVerification tag.
The API token is passed in the Authorization header.
Because the request body is lengthy, it is truncated in this example Curl section. See the full body in the Request body section. You can download or copy the example request body to try it out on your own. Before using it, make sure that you're using management zone and tags that are available in your environment.
The response code of 204 indicates that the update was successful.
Curl
curl -X PUT \https://mySampleEnv.live.dynatrace.com/api/config/v1/calculatedMetrics/service/calc:service.requestsbycode \-H 'Accept: Accept: application/json; charset=utf-8' \-H 'Authorization: Api-Token dt0c01.abc123.abcdefjhij1234567890' \-H 'Content-Type: application/json' \-d '{<truncated - see the Request body section >}'
Request URL
https://mySampleEnv.live.dynatrace.com/api/config/v1/calculatedMetrics/service/calc:service.requestsbycode
Request body
{"tsmMetricKey": "calc:service.requestsbycode","name": "Requests by code","enabled": true,"metricDefinition": {"metric": "REQUEST_COUNT","requestAttribute": null},"unit": "COUNT","unitDisplayName": "","entityId": null,"managementZones": ["Easytravel"],"conditions": [{"attribute": "PROCESS_GROUP_TAG","comparisonInfo": {"type": "TAG","comparison": "TAG_KEY_EQUALS","value": {"context": "CONTEXTLESS","key": "payment"},"negate": false}},{"attribute": "PROCESS_GROUP_TAG","comparisonInfo": {"type": "TAG","comparison": "TAG_KEY_EQUALS","value": {"context": "CONTEXTLESS","key": "cardVerification"},"negate": false}}],"dimensionDefinition": {"name": "HTTP Status class","dimension": "{HTTP-StatusClass}","placeholders": [],"topX": 10,"topXDirection": "DESCENDING","topXAggregation": "SINGLE_VALUE"}}
Response code
204