環境: Ubuntu 14.04
1. 安裝相依套件
sudo apt-get install unzip libwww-perl libdatetime-perl
2. 下載 script
cd ~/
curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O
unzip CloudWatchMonitoringScripts-1.2.1.zip
rm CloudWatchMonitoringScripts-1.2.1.zip
cd aws-scripts-mon
3. 把 script 加到 cronjob 定期執行
*/5 * * * * ~/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --disk-path=/ --from-cron
記得請先建立以下權限的 policy
cloudwatch:GetMetricStatistics
cloudwatch:ListMetrics
cloudwatch:PutMetricData
ec2:DescribeTags
4. AWS 建立一個 IAM policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AwsScriptsMonCW",
"Effect": "Allow",
"Action": [
"cloudwatch:GetMetricStatistics",
"cloudwatch:ListMetrics",
"cloudwatch:PutMetricData"
],
"Resource": [
"*"
]
},
{
"Sid": "AwsScriptsMonEC2",
"Effect": "Allow",
"Action": [
"ec2:DescribeTags"
],
"Resource": [
"*"
]
}
]
}
在這邊因為我們 ubuntu 是一個 ec2 instance 所以不用設定 AWSAccessKeyId 、 AWSSecretKey
你可以在 CloudWatch 的 Linux System Metrics 找到剛剛的 log 了
記得設定 Alarm 阿
沒有留言:
張貼留言