5. JSON transform

AWS cloudwatch metrics can be listed using the list-metrics operation, which generates a response like this:

{
    "Metrics": [
        {
            "Namespace": "AWS/RDS",
            "MetricName": "DBLoad",
            "Dimensions": [
                {
                    "Name": "DBInstanceIdentifier",
                    "Value": "mydbinstance"
                }
            ]
        },
        {
            "Namespace": "AWS/RDS",
            "MetricName": "FreeableMemory",
            "Dimensions": [
                {
                    "Name": "DBInstanceIdentifier",
                    "Value": "mydbinstance"
                }
            ]
        },
        {
            "Namespace": "AWS/RDS",
            "MetricName": "ReadIOPS",
            "Dimensions": [
                {
                    "Name": "DBInstanceIdentifier",
                    "Value": "mydbinstance"
                }
            ]
        },
        ...
    ]
}

We can transform the above response into a “metric widget request” (compatible with get-metric-widget-image), to let us graph these metrics. This results in the following compact JSON:

{"metrics":[["AWS/RDS","DBLoad","DBInstanceIdentifier","mydbinstance"],["AWS/RDS","FreeableMemory","DBInstanceIdentifier","mydbinstance"],["AWS/RDS","ReadIOPS","DBInstanceIdentifier","mydbinstance"]]}

Note: metrics is an array of arrays. Each sub-array contains the namespace and metric name, followed by the dimensions.


Transform this json file of 25 metrics: metrics.json into a “metric widget request” of compact JSON containing all the metrics.