Skip to content

Auto scale EC2 capacity, based on CPU and memory metrics. Slack message upon auto-scaling. Monitor metrics through CloudWatch dashboard.

Notifications You must be signed in to change notification settings

rdok/aws-ec2-autoscale-monitor-slack

Repository files navigation

Autoscale based on CPU and memory metrics. Monitor, slack.

  1. Monitor EC2 memory, disk, and CPU utilization using CloudWatch agent.
  2. Create dashboard with the metrics, and alert through slack when any alarm goes in alert status.
  3. Auto increase EC2 desired capacity, when CPU OR memory utilisation is greater than a threshold.
  4. Auto decrease EC2 desired capacity, when CPU AND memory utilisation is lower than a threshold.

dashboard
auto-scale
slack

Stress Test

sudo amazon-linux-extras install -y epel
sudo yum install -y stress htop

# CPU, and memory stress. t3.medium 2 CPU, 4GB memory
sudo stress --cpu 2 --vm-bytes $(awk '/MemAvailable/{printf "%d\n", $2 * 0.9;}' < /proc/meminfo)k --vm-keep -m 5

# Memory stress. t3.medium CPU, 4GB memory
sudo stress --vm-bytes $(awk '/MemAvailable/{printf "%d\n", $2 * 0.9;}' < /proc/meminfo)k --vm-keep -m 5
 
 # Disk utilization. 8GB disk
df -h
dd if=/dev/urandom of=2GB.bin bs=64M count=32 iflag=fullblock
dd if=/dev/urandom of=3GB.bin bs=64M count=48 iflag=fullblock
df -h

Debug

  • The subnets are public to keep the stack simple; the focus is to showcase memory, cpu utilization and the autoscaling.
  • Use the EC2 serial console to connect the instance.

The EC2 password is set to secret from the UserData. This is set ONLY for debugging purposes, so do we remove this command before using it on production.

Development

Sources

About

Auto scale EC2 capacity, based on CPU and memory metrics. Slack message upon auto-scaling. Monitor metrics through CloudWatch dashboard.

Topics

Resources

Stars

Watchers

Forks