Search code examples
amazon-cloudwatchaws-cloudwatch-log-insights

adding metric pattern in cloudwatch dashboard json


so I have created custom dashboard in AWS cloudwatch using json

{
            "height": 6,
            "width": 6,
            "y": 54,
            "x": 0,
            "type": "metric",
            "properties": {
                "view": "timeSeries",
                "stacked": false,
                "metrics": [
                    [ "service-es-dashboard","fact-bulk-loader","service", "es-dashboard" ]
                ],
                "region": "us-east-1",
                "title": "ES-documents-count"
            }
        }

and my metric array has different metric names like fact-bulk-loader-1, fact-bulk-loader-2 enter image description here

now i want to add all the metric name present in the metric array in my widget in dashboard how do i do that ? i can add a metric name and see but i want the process to be dynamic as every week new metrics gets added into the mertic array


Solution

  • You can use a search expression.

    The metrics part would look something like this:

    "metrics": [
        [ { "expression": "SEARCH('{service-es-dashboard,service} service=\"es-dashboard\" MetricName=\"fact-bulk-loader', 'Average', 300)", "id": "e2", "period": 300 } ]
    ]