CloudWatch Logs Insights

CloudWatch Logs Insights

  1. You access the EC2 interface
  • Select Instances
  • Select /Instance-A/test-instance
  • Then select Connect

CloudWatch

  1. In the Connect to instance interface
  • Select Session Manager
  • Select Connect

CloudWatch

  1. We will have a new interface on the browser

CloudWatch

  1. After accessing the Session Manager interface. You execute the following script:
cd /tmp
sudo aws s3 cp s3://workshop-template-bucket/logger.py .

CloudWatch

  1. Continue granting permission by running the next script
sudo chmod +x logger.py
python3 logger.py &

CloudWatch

5 . We check again with the following command:

 ps -aux | grep logger

CloudWatch

  1. View the log with the following command:
sudo tail -f /var/log/messages

CloudWatch

Find logs in CloudWatch Log Insights

  1. Access to CloudWatch interface
  • Select Logs Insights
  • Select Select log group(s)

CloudWatch

  1. Select /ec2/linux/var/log/messages.

CloudWatch

  1. Execute Run query
fields @timestamp, @message
| sort @timestamp desc
| limit 20

CloudWatch

  1. Notice that we are querying the logs from the past one hour, select Custom

CloudWatch

  1. We will see the following log:

CloudWatch

  1. Filter error logs
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| limit 20

CloudWatch

  1. View logs containing WARN
fields @timestamp, @message
| filter @message like /WARN/
| sort @timestamp desc
| limit 20

CloudWatch

  1. Then retry running the query ERROR
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| stats count (*) by @logStream

CloudWatch

  1. Continue query
fields @timestamp, @message
| filter @message like /eth0/
| sort @timestamp desc
| stats count (*) by bin(5m)

CloudWatch

  1. Then you see Visualization

CloudWatch

  1. Execute Save query
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| limit 20

CloudWatch

  1. Save query successfully.

CloudWatch

  1. View query history.

CloudWatch