2016년 6월 25일 토요일

AWS CloudWatch 메모리 감시 | AWS CloudWatch Memory Monitoring

Step 1
Make a policy for CloudWatch monitoring at IAM.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "cloudwatch:GetMetricStatistics",
                "cloudwatch:ListMetrics",
                "cloudwatch:PutMetricData",
                "ec2:DescribeTags"
            ],
            "Effect": "Allow",
            "Resource": "*"
        }
    ]
}

Step 2
Add CloudWatch monitoring policy to an IAM user, and get AWSAccessKeyID and AWSSecretKey .

Step 3
Run this script.

#!/bin/bash
set -e

sudo su -p <<HERE
# yum packages
yum -y install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https

# install cloudwatch monitoring scripts
cd /opt/aws
curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O
unzip CloudWatchMonitoringScripts-1.2.1.zip
rm -rf CloudWatchMonitoringScripts-1.2.1.zip
touch /opt/aws/aws-scripts-mon/awscreds.conf

# awscreds
echo 'AWSAccessKeyId=XXXXXXXXXXXXXXXX' >> /opt/aws/aws-scripts-mon/awscreds.conf
echo 'AWSSecretKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' >> /opt/aws/aws-scripts-mon/awscreds.conf

# crontab
echo '*/1 * * * * /opt/aws/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail' >> mycron
crontab mycron
rm -rf mycron
HERE

Step 4
Now you can get metrics about memory at CloudWatch.

댓글 없음:

댓글 쓰기