description |
---|
This page provides the technical details of the Assign Metrics policy |
{% hint style="warning" %} This feature requires Gravitee's Enterprise Edition. {% endhint %}
You can use the assign-metrics
policy to push extra metrics in addition to the natively provided request metrics.
These metrics can then be used from analytics dashboards to create custom widgets and, optionally, apply aggregations based on their value.
Functional and implementation information for the assign-metrics
policy is organized into the following sections:
{% hint style="warning" %} This policy can be applied to v2 APIs, v4 HTTP proxy APIs, and v4 message APIs. It cannot be applied to v4 TCP proxy APIs. {% endhint %}
{% tabs %} {% tab title="HTTP proxy API example" %} To display your request distribution based on a particular HTTP header in your dashboards, create the custom metric shown below:
"assign-metrics": {
"metrics": [
{
"name": "myCustomHeader,
"value": "{#request.headers['X-MyCustomHeader'] != null ? #request.headers['X-MyCustomHeader'][0] : null}"
}
]
}
{% endtab %}
{% tab title="Message API example" %} An example of this policy applied at the message level is shown below:
{
"id": "subscribe-assign-metrics",
"name": "subscribe-assign-metrics",
"apiVersion": "1.0",
"definitionVersion": "4.0.0",
"type": "message",
"analytics": {},
"description": "subscribe-assign-metrics",
"listeners": [
{
"type": "http",
"paths": [
{
"path": "/subscribe-assign-metrics"
}
],
"entrypoints": [
{
"type": "sse",
"configuration": {
"heartbeatIntervalInMs": 5000,
"metadataAsComment": false,
"headersAsComment": true
}
}
]
}
],
"endpointGroups": [
{
"name": "default",
"type": "mock",
"endpoints": [
{
"name": "default",
"type": "mock",
"weight": 1,
"inheritConfiguration": false,
"configuration": {
"messageInterval": 500,
"messageContent": "custom-metric",
"messageCount": 12
}
}
]
}
],
"flows": [
{
"name": "test-flow",
"enabled": true,
"selectors": [
{
"type": "channel",
"operation": ["SUBSCRIBE"],
"channel": "/",
"channel-operator": "STARTS_WITH"
}
],
"request": [],
"response": [],
"subscribe": [
{
"name": "Assign metrics",
"description": "",
"enabled": true,
"policy": "policy-assign-metrics",
"configuration": {
"metrics": [
{
"name": "content",
"value": "{#message.content}"
},
{
"name": "recordable",
"value": "{#message.attributes['message.recordable']}"
},
{
"name": "static",
"value": "value"
}
]
}
}
],
"publish": []
}
]
}
{% endtab %} {% endtabs %}
You can enable or disable the policy with policy identifier policy-assign-metrics
.
The phases checked below are supported by the assign-metrics
policy:
v2 Phases | Compatible? | v4 Phases | Compatible? |
---|---|---|---|
onRequest | true | onRequest | true |
onResponse | true | onResponse | true |
onRequestContent | true | onMessageRequest | true |
onResponseContent | true | onMessageResponse | true |
The following is the compatibility matrix for APIM and the assign-metrics
policy:
Plugin Version | Supported APIM versions |
---|---|
1.x | Up to 3.1.7 |
2.x | 3.18 to 3.20 |
3.x | 4.0+ |