Custom Metrics Agent Installation – Linux Ubuntu
Learn how to install CWAgent custom metrics and improve AWS cloud monitoring.
There is no configuration required on CleanCloud, all steps must be done from your AWS panel.
1.Go to the AWS System Manager Parameter Store page to create a parameter.
2.Click the Create parameter button.
3.Set AmazonCloudWatch-linux to name, select Standard and choose String type. Paste the JSON content below. Finally, click Create Parameter.
{
“metrics”:{
“append_dimensions”:{
“AutoScalingGroupName”:“${aws:AutoScalingGroupName}”,
“ImageId”:“${aws:ImageId}”,
“InstanceId”:“${aws:InstanceId}”,
“InstanceType”:“${aws:InstanceType}”
},
“metrics_collected”:{
“disk”:{
“measurement”:[
“disk_total”,
“disk_used”
],
“metrics_collection_interval”:300,
“ignore_file_system_types”:[
“tmpfs”,
“devtmpfs”,
“rootfs”,
“sysfs”
],
“resources”:[
“*”
]
},
“mem”:{
“measurement”:[
“mem_total”,
“mem_used”
],
“metrics_collection_interval”:300
},
“swap”:{
“measurement”:[
“swap_used”,
“swap_used_percent”
],
“metrics_collection_interval”:300
}
}
}
}
4.Once created, follow the next steps.
5.You must add two permissions to CWAgent:
AmazonEC2RoleforSSM and CloudWatchAgentServerPolicy through AWS Managed polices in the IAM Role for EC2 instances.
This IAM Role must be attached to EC2 instances. If you already have an IAM Role in use on the EC2 you only need to add the AmazonEC2RoleforSSM and CloudWatchAgentServerPolicy permissions.
6.On the Create Role page select AWS Service and EC2 as Service. Click Next to continue.
7.Select AmazonEC2RoleforSSM policy.
8.Select CloudWatchAgentServerPolicy policy and click Next.
9.After this step there is the tags screen. There is no need to add tags. Click Next:Review.
10.On the preview page, add the role name and verify that the correct policies are applied then click Create Role.
11.You must install the CWAgent in all instances in order to collect metrics. You can perform this process individually on each machine or automate this step by installing the bash script in the devops routine.
12.Follow the script below to perform such installation.
#!/bin/bash
cd /home/ubuntu
wgethttps://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb
sudo dpkg -i amazon-ssm-agent.deb
sudo rm -rf amazon-ssm-agent.deb
mkdir cwAgentPackage
cd cwAgentPackage
wgethttps://s3.amazonaws.com/amazoncloudwatch-agent/linux/amd64/latest/AmazonCloudWatchAgent.zip
sudo apt-get install -y –force-yes unzip
unzip AmazonCloudWatchAgent.zip
sudo chmod +x install.sh
sudo ./install.sh
cd ..
sudo rm -rf cwAgentPackage
## JSON file stored via ParameterStore called AmazonCloudWatch-linux
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-linux -s
sudo service amazon-ssm-agent restart
CONGRATULATIONS!
The agent now sends CloudWatch metrics that are collected by CleanCloud and will be available within 12 hours to use in dashboards and insights.
Got a question?
What is CloudWatch?
https://aws.amazon.com/pt/cloudwatch/
What is SSM?
https://docs.aws. amazon.com/systems-manager/ latest / userguide / ssm-agent. html
What is CWAgent?