How CloudWatch receives entries from simulated log
This is the fifth phase of this project. This phase is a combination of three tasks. I will show every task step by step.
In this phase, you will see how CloudWatch receives data from simulated log.
Task 1: Analyzing the simulated log file
There is a folder, named “samplelogs” in the left side menu in Cloud9. To see a few lines from it, run the following command —
cat samplelogs/access_log.log | head
To see first line of the log, run this command -
cat samplelogs/access_log.log | head -1 | python -m json.tool
Then if you want to see how many lines in this file, run this command -
cat samplelogs/access_log.log| wc -l
Task 2: Using the new log file
First you have to stop your CloudWatch agent. Run following command —
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a stop
Then check it’s status —
sudo service amazon-cloudwatch-agent status
Now you have to keep this simulated log file into the folder where CloudWatch expects it. In phase three, I show there is a configuration file where it states that CloudWatch will expect it’s access log into /var/log/www/access/*. See the following image —
So, you have to copy your simulated log file into this folder. You can do that by running following command —
sudo cp /home/ec2-user/environment/samplelogs/access_log.log /var/log/www/access/access_log
Now, it’s time to restart your Cloud agent again —
sudo systemctl restart amazon-cloudwatch-agent.service
Check status —
sudo service amazon-cloudwatch-agent status
Task 3: Confirming that the new logs appear in the CloudWatch log group
First, you have to CloudWatch console page. Then choose “Log groups” from it and double click on “apache/access” folder.
You will see a generated log file into this folder.
After clicking on log file you will see detail information of the log.
Congratulations!!! You have done one more phase. Go to next phase.
If you find this post helpful, please give a clap in this post and follow me in medium and lets connected in linked in.