Перейти к содержимому

AWS CloudWatch on EC2 Logs, Alarms and Email Alerts

Pranati_knowledgeBucks_ IT-to-IT

0:00 / 0:00

AWS CloudWatch on EC2 Logs, Alarms and Email Alerts

40 просмотров · 2 дня назад
Pranati_knowledgeBucks_ IT-to-IT
107 подписчиков
40 просмотров · 2 дня назад
Commands used (Ubuntu on EC2). Full document with app.py and config.json: [https://drive.google.com/file/d/1Mcwn...] -- Install -- sudo -i apt-get update -y apt-get install -y python3-flask stress wget -- Check the app file, then run it -- cd /home/ubuntu python3 -m py_compile app.py && echo VALID nohup python3 app.py & -- Create log lines -- curl -s localhost:5000/ curl -s localhost:5000/error chmod 644 /home/ubuntu/app.log cat /home/ubuntu/app.log -- Install the CloudWatch Agent -- cd /tmp U=https://amazoncloudwatch-agent.s3.ama... wget $U/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb dpkg -i -E ./amazon-cloudwatch-agent.deb ls /opt/aws/amazon-cloudwatch-agent/bin/ -- Check the config file -- wc -l /opt/aws/amazon-cloudwatch-agent/bin/config.json python3 -m json.tool /opt/aws/amazon-cloudwatch-agent/bin/config.json -- Start the agent -- /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status systemctl status amazon-cloudwatch-agent --no-pager -- Generate CPU load for the alarm -- stress --cpu 2 --timeout 600 & top -bn1 | head -5 uptime -- Stop everything -- /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop pkill -f "python3 app.py" -- If the agent sends nothing -- tail -40 /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log app.py and config.json are created with cat blocks, which cannot be shown here because YouTube does not allow angle brackets. Both files are in the PDF above. Console steps: IAM role (CloudWatchAgentServerPolicy) · CloudWatch Logs · Classic metrics · SNS topic and confirm the email · CPU alarm at 70% · dashboard · terminate the instance.