CloudWatch Logs Insights

CloudWatch Logs Insights

  1. Bạn truy cập vào giao diện EC2
  • Chọn Instances
  • Chọn /Instance-A/test-instance
  • Sau đó, chọn Connect

CloudWatch

  1. Trong giao diện Connect to instance
  • Chọn Session Manager
  • Chọn Connect

CloudWatch

  1. Chúng ta sẽ có một giao diện mới trên trình duyệt

CloudWatch

  1. Sau khi truy cập vào giao diện Session Manager. Bạn thực hiện chạy đoạn script sau:
cd /tmp
sudo aws s3 cp s3://workshop-template-bucket/logger.py .

CloudWatch

  1. Tiếp tục cấp quyền bằng cách chạy đoạn script tiếp theo
sudo chmod +x logger.py
python3 logger.py &

CloudWatch

5 . Chúng ta kiểm tra lại bằng lệnh sau:

 ps -aux | grep logger

CloudWatch

  1. Xem log bằng lệnh sau:
sudo tail -f /var/log/messages

CloudWatch

Tìm log trong CloudWatch Log Insights

  1. Truy cập vào giao diện CloudWatch*
  • Chọn Logs Insights
  • Chọn Select log group(s)

CloudWatch

  1. Chọn /ec2/linux/var/log/messages.

CloudWatch

  1. Thực hiện Run query
fields @timestamp, @message
| sort @timestamp desc
| limit 20

CloudWatch

  1. Notice that we are querying the logs from the past one hour, chọn Custom

CloudWatch

  1. Chúng ta sẽ thấy log như sau:

CloudWatch

  1. Lọc những log lỗi
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| limit 20

CloudWatch

  1. Xem các log chứa WARN
fields @timestamp, @message
| filter @message like /WARN/
| sort @timestamp desc
| limit 20

CloudWatch

  1. Sau đó thử lại chạy query ERROR
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| stats count (*) by @logStream

CloudWatch

  1. Tiếp tục query
fields @timestamp, @message
| filter @message like /eth0/
| sort @timestamp desc
| stats count (*) by bin(5m)

CloudWatch

  1. Sau đó bạn xem Visualization

CloudWatch

  1. Thực hiện Save query
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| limit 20

CloudWatch

  1. Save query thành công.

CloudWatch

  1. Xem lịch sử các query.

CloudWatch