CloudWatch Agent alarms not displayed

0

Hey,

I have successfully configered CloudWatch Agent on a EC2 instance and can view the metrics in the "All metrics" section. When creating an alarm from these metrics, the alarm shows "insufficient data" and doesn´t display any metric.

The logs does´nt show anything suspicious.

The configuration:

{
        "agent": {
                "metrics_collection_interval": 60,
                "run_as_user": "root"
        },
        "logs": {
                "logs_collected": {
                        "files": {
                                "collect_list": [
                                        {
                                                "file_path": "/var/log/messages",
                                                "log_group_name": "cwagentlogs",
                                                "log_stream_name": "{instance_id}",
                                                "retention_in_days": 1
                                        }
                                ]
                        }
                }
        },
        "metrics": {
                "aggregation_dimensions": [
                        [
                                "InstanceId"
                        ]
                ],
                "append_dimensions": {
                        "AutoScalingGroupName": "${aws:AutoScalingGroupName}",
                        "ImageId": "${aws:ImageId}",
                        "InstanceId": "${aws:InstanceId}",
                        "InstanceType": "${aws:InstanceType}"
                },
                "metrics_collected": {
                        "cpu": {
                                "measurement": [
                                        "cpu_usage_idle",
                                        "cpu_usage_iowait",
                                        "cpu_usage_user",
                                        "cpu_usage_system"
                                ],
                                "metrics_collection_interval": 60,
                                "resources": [
                                        "*"
                                ],
                                "totalcpu": false
                        },
                        "disk": {
                                "measurement": [
                                        "used_percent",
                                        "inodes_free"
                                ],
                                "metrics_collection_interval": 60,
                                "resources": [
                                        "*"
                                ]
                        },
                        "diskio": {
                                "measurement": [
                                        "io_time",
                                        "write_bytes",
                                        "read_bytes",
                                        "writes",
                                        "reads"
                                ],
                                "metrics_collection_interval": 60,
                                "resources": [
                                        "*"
                                ]
                        },
                        "mem": {
                                "measurement": [
                                        "mem_used_percent"
                                ],
                                "metrics_collection_interval": 60
                        },
                        "netstat": {
                                "measurement": [
                                        "tcp_established",
                                        "tcp_time_wait"
                                ],
                                "metrics_collection_interval": 60
                        },
                        "swap": {
                                "measurement": [
                                        "swap_used_percent"
                                ],
                                "metrics_collection_interval": 60
                        }
                }
        }

Can anyone help me with this issue?

BR, Mark

asked 8 months ago436 views
3 Answers
0
Accepted Answer

Oh you're mentioning the namespace AWS/EC2 in your alarm configuration, but only metrics collected directly by the EC2 service will be reported with that namespace. The metrics collected by the CloudWatch agent will be reported with a different namespace. I believe the namespace should be CWAgent rather than AWS/EC2.

profile pictureAWS
Jsc
answered 8 months ago
profile pictureAWS
EXPERT
reviewed 8 months ago
0

Hi, if you can view the metrics in the "All metrics" section, then the agent configuration is OK and it is not likely the place to look for an issue.

The most common issue that leads to an alarm staying in insufficient data when created on a metric that you can view in the console is if you specify an unit on the alarm and that unit doesn't match the metric's unit.

How did you create your alarms and can you share the definition of one of your alarms?

profile pictureAWS
Jsc
answered 8 months ago
  • Hey,

    I create them with a CloudFormation template:

    EC2MemoryUsage1: Type: 'AWS::CloudWatch::Alarm' DependsOn: SNSTopic Properties: AlarmName: !Sub '${CustomerName}-QAS-Submission-MemoryUsage' AlarmDescription: 'Alarm for Memory Usage > 90% on EC2 Instance' AlarmActions: - !Ref SNSTopic Namespace: 'AWS/EC2' MetricName: 'mem_used_percent' Dimensions: - Name: 'InstanceId' Value: !Ref QASSubmissionEC2InstanceId ComparisonOperator: 'GreaterThanThreshold' Threshold: 90 EvaluationPeriods: 1 Period: 21600 #6 hours Statistic: 'Average'

    I forgot to mention that I deploy the template in the CloudWatch Monitoring account and the data is grapped from a source account. I followed this page: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Cross-Account-Cross-Region.html When I create the alarm in the source account it works.

0

And sorry noticed after previous answer, if you create the alarm in a different account than the source account, you must also mention the account id.

Example:
    Metrics:
        - Id: m1
          ReturnData: true
          AccountId: "123456789012"
          MetricStat:
              Metric:
                  Namespace: CWAgent
                  MetricName: mem_used_percent
                  Dimensions: …
              Period: 21600
              Stat: Average

profile pictureAWS
Jsc
answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions