I find AWS CloudWatch very useful when it comes to monitor system/application logs. CloudWatch service provides a friendly UI to search inside your logs. Also it offers very flexible way to select logs of specific date or date range.
What I m trying to do
I will try to explain how it s easy to install and configure AWS CloudWatch on my EC2 instance and create Alarms on the logs.
- EC2 instance running ubuntu machine 16.04
- awscli must be installed and configured.
- Download and Install aws CloudWatch agent on our machine
- Setup the Cloudwatch Agent
- Configure an alarm
Amazon makes the installation of the CloudWatch agent very easy.
- make sure you run the command as root.
MY_REGION : is the region of your running EC2 instance ( for example : us-east-1 )
- there are two way of configuring the CloudWatch agent, either using the interactive mode or non interactive mode. let’s start with the interactive mode.
You will prompted to fill some details
- AWS Access Key ID : write or paste your Aws Access ID and hit enter.
- AWS Secret Access Key : the same goes for secret keys. (you can get always get news keys from the IAM console).
- Default region name : region name in this case it will be the name of region we put in the command.
- Default output format [None]: leave it blank unless you have another format.
- Path of log file to upload: the absolute path of the file you want to monitor, for example [/var/log/syslog].
- Destination Log Group name : This allows you to group your logs by name, you can you create different groups for your logs for instance ( staging, production, … ).
- Last thing is the stream name, you can you instance ID or custom.
Non Interactive Mode:
- first you need to create a file with the following configuration, we you use this file in the next command.
- after the instalation go the following direcotry [/var/awslogs/etc] and make sure that [aws.conf] has your access ID and secret key. aws.conf must look something like this
- then restart the aws logs agent