===== AWS CloudWatch ===== {{tag>AWS Linux}} ==== Current ==== Amazon has made it much easier to use the Amazon CloudWatch Agent by making it open source (https://github.com/aws/amazon-cloudwatch-agent/), available via package managers, and including a configuration wizard. Here are my notes on my initial testing. * Update EC2 instance role to include new IAM policy ''CloudWatchAgentServerPolicy'' * https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-iam-roles-for-cloudwatch-agent-commandline.html * Install CloudWatch Agent via yum * ''sudo yum -y install amazon-cloudwatch-agent'' * https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/download-cloudwatch-agent-commandline.html * Run the Amazon CloudWatch Agent Configuration Wizard * ''sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard'' * If you are using another agent like DataDog you will not be able to use StatsD * If you wish to use collectd you will need to install and configure it * Start the Amazon CloudWatch Agent * ''sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl'' * The default config file location used by the configuration wizard is ''/opt/aws/amazon-cloudwatch-agent/bin/config.json'' * If you receive error messages try disabling StatsD and collectd via the configuration wizard * https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/troubleshooting-CloudWatch-Agent.html Example command to start the CloudWatch Agent sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \ -a fetch-config \ -m ec2 \ -s \ -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json Amazon also has CloudFormation templates that will pre-install and configure the Amazon CloudWatch Agent.\\ https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent-New-Instances-CloudFormation.html ==== Previous ==== { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "cloudwatch:PutMetricData" ], "Resource": [ "*" ] }, { "Effect": "Allow", "Action": [ "cloudwatch:GetMetricStatistics" ], "Resource": [ "*" ] }, { "Effect": "Allow", "Action": [ "cloudwatch:ListMetrics" ], "Resource": [ "*" ] }, { "Effect": "Allow", "Action": [ "ec2:DescribeTags" ], "Resource": [ "*" ] } ] } */5 * * * * /root/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail ---- http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html