A Node.js package that scales your application servers by publishing custom CloudWatch metrics which are not available by default, such as:
- Memory Available - amount of system memory available
- Sockets Used - number of open client/server connections
Scalemate supports per-second metric resolution and defaults to per-minute.
First, install the package using npm:
npm install -g scalemate
Then, create a file called
config.js and paste the following inside it:
moduleexports =// Metrics to publishmetrics:// Number of open socket connectionssocketsUsed:// Whether to publish this metricenabled: true// CloudWatch unit typeunit: 'Count'// CloudWatch metric titlename: 'Sockets Used'// Number of megabytes of system memory currently availablememoryAvailable:// Whether to publish this metricenabled: true// CloudWatch unit typeunit: 'Count'// CloudWatch metric titlename: 'Memory Available'// Metric interval (in seconds)interval: 60// CloudWatch namespace to associate metrics withnamespace: 'MyApp'// AWS IAM user with CloudWatch read/write accesscredentials:region: 'us-east-1'accessKeyId: 'ABCDEFG'secretAccessKey: 'ABCDEFGHIJK/HIJKLMNOPQRS';
Modify the configuration file according to your own needs, enabling or disabling metrics and configuring the following parameters:
namespace- the name of your app or server cluster
credentials- an AWS IAM user with read/write access to CloudWatch
Test the configuration by running:
Observe the terminal output for any initial errors and for successfully-published metrics. If no errors are emitted, you have successfully configured Scalemate.
Visit the CloudWatch console and find the published metrics under the Scalemate namespace: https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#
You can now configure CloudWatch alarms to scale your EC2 instances up or down based on these metrics.
Leave the tool running on a remote server by executing the following command:
scalemate > /tmp/scalemate.log &
To start Scalemate automatically after system reboots, add the following to your user's
@reboot scalemate -c /path/to/config.js > /tmp/scalemate.log &