Hello,
I am looking for advice on how to agregate multiple numeric values into a single value from a list of dimension values.
- What Grafana version and what operating system are you using?
Amazon Managed Grafana 10.4.1 using the cloudwatch data source
- What are you trying to achieve?
We are creating success rate panels using Stats.
Example will use Lambda, but same issue with API Gateway and other queries with multiple dimensions like this.
- How are you trying to achieve it?
Starting with a query variable $function. This is a list of all FunctionNames to include.
In a visualisation, there are 2 Cloudwatch metrics queries, one for Invocations and another for Errors, each grouped by FunctionName.
Passing in $function as the dimension value for FunctionName successfully retrieves the time series data for Invocations/Errors of the listed functions.
Each query is passed to a Reduce expression and that reduce is then used in a math expression.
- What happened?
For queries where thereâs no dimension passed, or where there is a single dimension passed, this works.
For multiple functions, the sums are still grouped by FunctionName.
- What did you expect to happen?
For this panel, we need to have a Total of all the Invocations/Erros combined to be used in the calculation.
- Can you copy/paste the configuration(s) that you are having problems with?
Example Panel JSON:
{
"datasource": {
"uid": "${datasource}",
"type": "cloudwatch"
},
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "#3274D9",
"value": null
},
{
"color": "dark-red",
"value": 85
},
{
"color": "#EAB839",
"value": 99.5
},
{
"color": "dark-green",
"value": 100
}
]
},
"unit": "percent"
},
"overrides": []
},
"gridPos": {
"h": 15,
"w": 15,
"x": 0,
"y": 12
},
"id": 4,
"options": {
"reduceOptions": {
"values": false,
"calcs": [],
"fields": ""
},
"orientation": "auto",
"textMode": "auto",
"wideLayout": true,
"colorMode": "background_solid",
"graphMode": "area",
"justifyMode": "center",
"showPercentChange": true
},
"pluginVersion": "10.4.1",
"title": "Lambda example",
"type": "stat",
"targets": [
{
"datasource": {
"type": "cloudwatch",
"uid": "..."
},
"id": "",
"region": "default",
"logGroups": [],
"queryMode": "Metrics",
"namespace": "AWS/Lambda",
"metricName": "Invocations",
"expression": "",
"dimensions": {
"FunctionName": "$function"
},
"statistic": "Sum",
"period": "",
"metricQueryType": 0,
"metricEditorMode": 0,
"sqlExpression": "",
"matchExact": true,
"stat": "Sum",
"refId": "Invocations",
"label": "",
"hide": true
},
{
"datasource": {
"type": "cloudwatch",
"uid": "..."
},
"id": "",
"region": "default",
"logGroups": [],
"queryMode": "Metrics",
"namespace": "AWS/Lambda",
"metricName": "Errors",
"expression": "",
"dimensions": {
"FunctionName": "$function"
},
"statistic": "Sum",
"period": "",
"metricQueryType": 0,
"metricEditorMode": 0,
"sqlExpression": "",
"matchExact": true,
"stat": "Sum",
"refId": "Errors",
"label": "",
"hide": true
},
{
"datasource": {
"type": "__expr__",
"uid": "__expr__",
"name": "Expression"
},
"refId": "ReducedInvocations",
"type": "reduce",
"hide": true,
"reducer": "sum",
"expression": "Invocations",
"settings": {
"mode": "replaceNN",
"replaceWithValue": 0
}
},
{
"datasource": {
"type": "__expr__",
"uid": "__expr__",
"name": "Expression"
},
"refId": "ReducedErrors",
"type": "reduce",
"hide": true,
"reducer": "sum",
"expression": "Errors",
"settings": {
"mode": "replaceNN",
"replaceWithValue": 0
}
},
{
"refId": "SuccessRate",
"type": "math",
"hide": false,
"expression": " ((${ReducedInvocations} - ${ReducedErrors}) / (${ReducedInvocations})) * 100"
}
],
"transformations": [
{
"id": "renameByRegex",
"options": {
"regex": "SuccessRate.*",
"renamePattern": "SuccessRate"
}
}
]
}
- Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
No errors.
- Did you follow any online instructions? If so, what is the URL?
I have searched the forum for similar issues and found this: Summing all fields matching certain pattern - #2 by usman.ahmad
The Rename by regex transformation successfully renames from FunctionName to SuccessRate, but then reducing with Add field from calculation does not produce a sum total of all the functions.
Please let me know if thereâs any more info needed.
Thanks,








