A project to automatically scale your DO droplets based on data gathered from NetData.
- Ruby - Tested with version 2.5.5
- Bundler for gem management
- Must be configured to run NetData automatically on startup
- Clone or download this repository
- Run
bundler install
to download gems (rungem install bundler
if bundler is not installed on your system) - Copy
config/config.example.yml
to a new file namedconfig/config.yml
- Enter your DigitalOcean API key in the appropriate line of
config/config.yml
- Configure your autoscaling environment with DigitalOcean tags, CPU Thresholds and Min/Max droplets
- Configure your droplet setup settings - helper commands are listed in comments, e.g.
ruby scaler.rb list regions
to list available droplet limits - Set your netdata port if it is different from default
ruby scaler.rb scale
Runs the autoscale function. This will gather information from the DO api about currently active droplets with the autoscaling tag set in config/config.yml
, gather CPU usage information from netdata, and scale up or down if thresholds are exceeded (and droplet limits allow).
In most use cases this command should be executed using a cron job on a regular interval - recommended interval is 60 seconds.
ruby scaler.rb list {type}
Lists configuration helper information from the DigitalOcean API. Type must be specified as one of the following:
ruby scaler.rb list images
Lists all available images including DO default and marketplace images - in most cases you'll want to use snapshots
instead. Use the ID
field in config file.
Example output:
+----------+----------------------------------------------+----------+-----------+---------------+
| Images |
+----------+----------------------------------------------+----------+-----------+---------------+
| ID | Name | Type | Size (GB) | Distribution |
+----------+----------------------------------------------+----------+-----------+---------------+
| 16376426 | Cassandra on 14.04 | snapshot | 0.59 | Ubuntu |
| 25256991 | 14.04.5 x32 | snapshot | 0.43 | Ubuntu |
| 28282122 | 10.4 x64 ZFS | snapshot | 0.75 | FreeBSD |
| 28282143 | 10.4 x64 | snapshot | 0.72 | FreeBSD |
| 28706758 | MachineLearning on 16.04-20171020 | snapshot | 1.87 | Ubuntu |
+----------+----------------------------------------------+----------+-----------+---------------+
...etc
ruby scaler.rb list keys
Lists available SSH keys that can be added to VMs. Use the ID
field in config file.
Example output:
+----------+----------------+
| SSH Keys |
+----------+----------------+
| ID | Name |
+----------+----------------+
| 19331324 | Home Key |
| 74063591 | Work Key |
+----------+----------------+
ruby scaler.rb list regions
Lists avilable DigitalOcean regions to deploy VMs in. Use the Slug
field in config file.
Example output:
+------+-----------------+-----------+
| Regions |
+------+-----------------+-----------+
| Slug | Name | Available |
+------+-----------------+-----------+
| nyc1 | New York 1 | true |
| sgp1 | Singapore 1 | true |
| lon1 | London 1 | true |
| nyc3 | New York 3 | true |
+------+-----------------+-----------+
...etc
ruby scaler.rb list sizes
Lists sizes available for VMs. Use the Slug
field in config file.
Example output:
+----------------+-------+-------------+-----------+--------------+
| Sizes |
+----------------+-------+-------------+-----------+--------------+
| Slug | VCPUs | Memory (MB) | Disk (GB) | Price ($/mo) |
+----------------+-------+-------------+-----------+--------------+
| 512mb | 1 | 512 | 20 | 5.0 |
| s-1vcpu-1gb | 1 | 1024 | 25 | 5.0 |
| 1gb | 1 | 1024 | 30 | 10.0 |
| s-1vcpu-2gb | 1 | 2048 | 50 | 10.0 |
| s-1vcpu-3gb | 1 | 3072 | 60 | 15.0 |
| s-2vcpu-2gb | 2 | 2048 | 60 | 15.0 |
+----------------+-------+-------------+-----------+--------------+
...etc
ruby scaler.rb list snapshots
Lists your VM snapshots - not including public images. Use the ID
field in config files.
Example output:
+----------+----------------------------------+-----------+--------------------+--------------+
| Snapshots |
+----------+----------------------------------+-----------+--------------------+--------------+
| ID | Name | Size (GB) | Min Disk Size (GB) | Distribution |
+----------+----------------------------------+-----------+--------------------+--------------+
| 49193223 | web-template-with-redis | 1.79 | 60 | droplet |
| 49289407 | gluster-02.macdara.tk 2019-07-06 | 1.87 | 60 | droplet |
+----------+----------------------------------+-----------+--------------------+--------------+
Shows more logging information for diagnostics. Can be quite chatty, don't use this for every script run.
- Add advanced error handling with better logging for debugging
- Add health checks with automatic restarting of unhealthy nodes
- Add scaling interval to limit how quickly nodes can be added / removed
Reformat output lists as tables for clearer outputDONE