Approach1. Using awscli (you don't have to make codes)
1. before collecting some metrics from your instance, your instance must be lauched with CloudWatchFullAccess IAM role.
ref: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/UsingIAM.html
Amazon CloudWatch integrates with AWS Identity and Access Management (IAM) so that you can specify which CloudWatch actions a user in your AWS Account can perform. For example, you could create an IAM policy that gives only certain users in your organization permission to use |
* in my case, I made new role(named cloudwatch_test) on IAM service with CloudWatchFullAccess, CloudWatchLogsFullAccess policies. and launch ec2 instance with this IAM role.
2. follow this. to install cloudwatch tool stuffs
http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/mon-scripts-perl.html
3. After installing perl stuffs and finishing role settings, you can use perl command like this.
now you can check your custom metric in Ec2 monitoring->View all CloudWatch metrics->Metrics-> Linux System Metrics
* if you want to monitor your existing ec2 instance, unfortunately there is no way. I tried below, but it was not working.
(you should install awscli tool first, just type $sudo apt-get install awscli, $aws configure)
1. aws iam create-instance-profile --instance-profile-name CloudWatchProfile
2. aws iam add-role-to-instance-profile --instance-profile-name CloudWatchProfile --role-name cloudwatch_test
Approach2. Using Boto (you have to do some works, but could be more flexible)
http://arr.gr/blog/2013/08/monitoring-ec2-instance-memory-usage-with-cloudwatch/
followed record.
1. make t2 micro ec2 instance (ubuntu)
2. install prerequisites
$sudo apt-get update
$sudo apt-get install python-pip
$sudo pip install boto
3. setup boto config file
$sudo vim /etc/boto.cfg
4. get source code and set to cron job
5. check it in AWS management console
Ec2 monitoring->View all CloudWatch metrics->Metrics-> Custom Metrics (it will take a time, wait until this menu created)
'aws' 카테고리의 다른 글
AWS lambda 삽질 일기 (0) | 2017.03.17 |
---|---|
kinesis firehose 삽질일기 (0) | 2017.03.16 |
elasticache dump to file (1) | 2015.03.23 |
[ubuntu server instance] mytoon setting (0) | 2014.10.24 |
HTTP 505: HTTP Version Not Supported (0) | 2014.07.09 |