Bootstrap FreeKB - Amazon Web Services (AWS) - List Cloudwatch metrics
Amazon Web Services (AWS) - List Cloudwatch metrics

Updated:   |  Amazon Web Services (AWS) articles

This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.

Cloudwatch alarms can be used to alert you when some condition is met, such as:

  • an EC2 instance has high CPU or high memory usage
  • an EC2 instance in a Load Balancer Target Group health check returns "unhealthy"
  • a Lambda Function has one or more errors

The aws cloudwatch describe-alarms command can be used to list the cloudwatch alarms you have created. Something like this should be returned.

~] aws cloudwatch describe-alarms
{
    "MetricAlarms": [
        {
            "AlarmName": "my-cloudwatch-alarm",
            "AlarmArn": "arn:aws:cloudwatch:us-east-1:123456789012:alarm:my-cloudwatch-alarm",
            "AlarmDescription": "CPU Utilization exceeds 10% in the last 5 minutes",
            "AlarmConfigurationUpdatedTimestamp": "2023-06-21T01:53:16.629000+00:00",
            "ActionsEnabled": true,
            "OKActions": [],
            "AlarmActions": [
                "arn:aws:sns:us-east-1:123456789012:my-topic"
            ],
            "InsufficientDataActions": [
                "arn:aws:sns:us-east-1:123456789012:my-topic"
            ],
            "StateValue": "OK",
            "StateReason": "Threshold Crossed: 1 datapoints [1.3967213114600159 (21/06/23 01:44:00)] was not greater than the threshold (10.0).",
            "StateReasonData": "{\"version\":\"1.0\",\"queryDate\":\"2024-01-16T06:23:48.140+0000\",\"startDate\":\"2024-01-16T06:20:00.000+0000\",\"unit\":\"Percent\",\"statistic\":\"Average\",\"period\":60,\"recentDatapoints\":[0.0015606770489069999],\"threshold\":10.0,\"evaluatedDatapoints\":[{\"timestamp\":\"2024-01-16T06:20:00.000+0000\",\"sampleCount\":1.0,\"value\":0.0015606770489069999}]}",
            "StateUpdatedTimestamp": "2023-06-21T01:54:00.144000+00:00",
            "MetricName": "CPUUtilization",
            "Namespace": "AWS/EC2",
            "Statistic": "Average",
            "Dimensions": [
                {
                    "Name": "InstanceId",
                    "Value": "i-0d241234f9665abcd"
                }
            ],
            "Period": 300,
            "Unit": "Percent",
            "EvaluationPeriods": 1,
            "Threshold": 10.0,
            "ComparisonOperator": "GreaterThanThreshold"
        }
    ],
    "CompositeAlarms": []
}

 

The aws cloudwatch get-metric-data command can be used to see if there have been any occurrences of the AWS service associated with a Cloudwatch alarm entering into whatever state is required for the Cloudwatch alarm to go into an In Error state. In this example, there are 5 occurrences of my-lambda-function going into an Error state.

~]$ aws cloudwatch get-metric-data --metric-data-queries '[{"Id":"m1","MetricStat":{"Metric":{"Namespace":"AWS/Lambda","MetricName": "Errors","Dimensions":[{"Name": "FunctionName", "Value":"my-lambda-function"}]},"Period": 60, "Stat":"Sum"},"ReturnData":true}]' --start-time "2025-11-18T00:00:00Z" --end-time "2025-11-18T14:00:00Z"
{
    "MetricDataResults": [
        {
            "Id": "m1",
            "Label": "Errors",
            "Timestamps": [
                "2025-11-18T13:49:00+00:00",
                "2025-11-18T13:48:00+00:00",
                "2025-11-18T13:37:00+00:00",
                "2025-11-18T13:23:00+00:00",
                "2025-11-18T12:05:00+00:00"
            ],
            "Values": [
                2.0,
                1.0,
                1.0,
                1.0,
                1.0
            ],
            "StatusCode": "Complete"
        }
    ],
    "Messages": []
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter bb5566 in the box below so that we can be sure you are a human.