Enable Memory and Disk Utilization Metric for Ubuntu Instance on AWS
1 min readAug 30, 2020
This article will illustrate you using CloudWatch for capturing Memory and Disk Utilization Metrics for Ubuntu Instance on AWS.
Step 1: Attach required permission
Ensuring EC2 has sufficient IAM Role to put data in CloudWatch. EC2 Instance Profile require the following permission in order to put data in Cloud Watch.
Create a policy with the following permission:
- cloudwatch:PutMetricData
- cloudwatch:GetMetricStatistics
- cloudwatch:ListMetrics
- ec2:DescribeTags
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*",
"cloudwatch:PutMetricData",
"cloudwatch:GetMetricStatistics",
"cloudwatch:ListMetrics"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
Step 2: Install the required package
sudo apt-get update
sudo apt-get install unzip
sudo apt-get install libwww-perl libdatetime-perl
Step 3: Install monitoring scripts
curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -Ounzip CloudWatchMonitoringScripts-1.2.2.zip && \
rm CloudWatchMonitoringScripts-1.2.2.zip && \
cd aws-scripts-mon
Step 4: Run the script in Cron
*/5 * * * * ~/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --mem-used --mem-avail --disk-space-util --disk-path=/ --disk-path=/dev --from-cron
Here, — from-cron is used to suppress all diagnostic output and error message are sent to the local system logs.