How to Configure CloudWATCH

Cloud watch is byright enabled by default (5minutes)
If you launch instances in EC2 → automatically log to cloudwatch
if you want 1 minute metrics → detailed monitoring for EC2
good video to watch : youtube.com/watch?v=bgRt3kiNt_Q
AWS docs : ……./UserGuide/mon-scripts.html

ANYWAYS to start..
Go into EC2 instance ssh

Preconfigured packages to enable the cloudwatch metrics (Perl Modules) -> this will enable to use monitoring scripts
>> sudo yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA.x86_64

Download custom monitoring scripts now ( these are written and provided by AWS)
>> curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -O

Unzip scripts and go into the downloaded directory
>> unzip CloudWatchMonitoringScripts-1.2.2.zip && \
rm CloudWatchMonitoringScripts-1.2.2.zip && \
cd aws-scripts-mon

THEN need to add roles to the EC2 instance -> in order to call other instances (this allows EC2 to write cloud logs to AWS)
>>CREATE ROLE >> Attach 1. AmazonEC2RoleforSSM 2. CloudWatchAgentAdminPolicy

Trigger the script (this will write log to cloud watch ONE TIME )
>> ./mon-put-instance-data.pl --mem-util --mem-used-incl-cache-buff --mem-used --mem-avail

(can trigger what you want)

HOW TO TRIGGER THIS EVERY 1 MINUTE — CRON JOB

>> FULL ADDRESS : /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl — mem-util — mem-used-incl-cache-buff — mem-used — mem-avail

ADD it as a cron job
>> crontab -e
>> */1 * * * * /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl — mem-util — mem-used-incl-cache-buff — mem-used — mem-avail
>> second, minute, hour, day, week, month
>> save and check
>> crontab -l

cf. Install the awslogs by rpm package (yum)
>>yum install -y awslogs