Skip to content

AWs Cloudwatch Alarm Disk Usage Linux EC2

-3

I have an EC2 Ubuntu instance with a root EBS and a secondary EBS. Randomly, after rebooting, the naming of mapped blocks get switched from nvme1n1 to nvme0n1 for root and secondary volume. There's no problem in that, since in fstab I specified the mounting through UUID, but when configuring an alarm in CW for disk usage, the swapping in device naming breaks the alarm, because it is monitoring a wrong device. Is there a solution? The problem happens just for this Ubuntu instances. Thank you all for the answers.

asked 2 years ago1.1K views
3 Answers
3

Hello,

To avoid CloudWatch alarm breakage due to device name swapping on your Ubuntu instance:

  • Use the UUID instead of the device name (nvme1n1 or nvme0n1) when configuring your CloudWatch disk usage alarm.

Using the AWS CLI, the command would look like this:

aws cloudwatch put-metric-alarm --alarm-name "DiskUsageAlarm-Root" --metric-name VolumeWriteOps --namespace AWS/EBS --statistic Sum --period 300 --threshold 100000 --comparison-operator GreaterThanOrEqualToThreshold --dimensions Name=VolumeId,Value=vol-xxxxxxxx --evaluation-periods 1 --alarm-actions arn:aws:sns:region:account-id:sns-topic-name

Replace vol-xxxxxxxx with your actual EBS volume ID.

This way, the alarm will consistently monitor the correct volume regardless of the device name assigned during boot. You already mentioned specifying the mounting through UUID in fstab, so extending that logic to CloudWatch will ensure reliable monitoring.

EXPERT
answered 2 years ago
1

Hello,

please try this solution it will be helpful for you.

CloudWatch monitors disk usage based on the mount point.

** 1 Install the CloudWatch Agent**

update the package.

sudo apt-get update

Install the CloudWatch Agent.

sudo apt-get install amazon-cloudwatch-agent

2 Configure the CloudWatch Agent

     a. Create or edit the CloudWatch Agent configuration file:

             Create or edit the configuration file located at /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
             use below example configuration.
{
    "agent": {
        "metrics_collection_interval": 60,
        "run_as_user": "root"
    },
    "metrics": {
        "metrics_collected": {
            "disk": {
                "measurement": [
                    "used_percent"
                ],
                "metrics_collection_interval": 60,
                "resources": [
                    "*"
                ]
            },
            "diskio": {
                "measurement": [
                    "io_time",
                    "read_bytes",
                    "write_bytes"
                ],
                "metrics_collection_interval": 60,
                "resources": [
                    "*"
                ]
            }
        }
    }
}

This configuration collects the used_percent metric for all disks and mount points save the configuration file.

3 Start the CloudWatch Agent

     a. Apply the configuration and start the agent
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s

4. Create the CloudWatch Alarm

         1. Open the CloudWatch console.
         2. Navigate to "Alarms" and click "Create Alarm."
         3. Select the metric namespace CWAgent.
         4. Choose the disk_used_percent metric and ensure you select the correct mount point (e.g., / or any specific mount point).
         5. Configure the threshold and actions for your alarm.
    

option

     we can use the AWS CLI commands, we can create alarm.
aws cloudwatch put-metric-alarm --alarm-name "DiskUsageAlarm" --metric-name "disk_used_percent" --namespace "CWAgent" --statistic "Average" --period 60 --evaluation-periods 1 --threshold 80 --comparison-operator "GreaterThanOrEqualToThreshold" --dimensions Name=path,Value=/ --actions-enabled --alarm-actions <Your-Alarm-Action-ARN>

Please look at AWS Document you will get more information.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-createalarm.html

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/viewing_metrics_with_cloudwatch.html

https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/metrics-collected-by-CloudWatch-agent.html

EXPERT
answered 2 years ago
-1
Accepted Answer

I also found this setting in json configuration file for disk alarm...didn't know it. drop_device = true ignore the devicename

	"metrics_collected": {
		"disk": {
			"measurement": [
				"used_percent"
			],
			"metrics_collection_interval": 60,
			"resources": [
				"/",
				"/DATABASES"
			],
			"drop_device": true
		},
answered 2 years 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.