node-heap-gc-cloudwatch

Report v8 heap usage and gc activity to CloudWatch

Usage no npm install needed!

<script type="module">
  import nodeHeapGcCloudwatch from 'https://cdn.skypack.dev/node-heap-gc-cloudwatch';
</script>

README

Build Status NPM version NPM dependencies NSP Status

node-heap-gc-cloudwatch

Send v8 heap statistics and garbage collection statistics to CloudWatch.

CloudWatch heap space used size graph

Getting started

Install the module:

npm install node-heap-gc-cloudwatch

In your app, create and start an agent:

var config = {};
require("node-heap-gc-cloudwatch")(config, function(err, agent) {
  if (err) {
    throw err;
  } else {
    agent.on("error", function(err) {
      console.log("error", err);
    });
    agent.start(function(err) {
      if (err) {
        throw err;
      } else {
        console.log("started");
      }
    });
  }
});

After ~1 minute you will see the first metrics in CloudWatch under the node name space.

Make sure to allow the cloudwatch:PutMetricData Action in your IAM policy.

Configuration

  • collectInterval: Number - Collect new heap statistics every collectInterval ms (default 1000)
  • writeInterval: Number - Send metric to CloudWatch every writeInterval ms (default 60000)
  • heapStatistics: Array[String] - Values to report to CloudWatch from v8.getHeapStatistics() (default ["total_heap_size", "total_heap_size_executable", "total_physical_size", "total_available_size", "used_heap_size", "heap_size_limit"])
  • heapSpaceStatistics: Array[String] - Values to report to CloudWatch from v8.getHeapSpaceStatistics() (default ["space_size", "space_used_size", "space_available_size", "physical_space_size"])
  • cloudwatch: AWS.CloudWatch - CloudWatch service object (default new AWS.CloudWatch())
  • namespace: String - The namespace for the metric data (default node)
  • dimensions: Object[String, String] - Add additional dimensions like {Application: "webshop", Environment: "production"}. (default {})
  • addProcessIdDimension: Boolean - If true, adds the ProcessId dimension with the value of process.pid (default false)
  • addInstanceIdDimension: Boolean - If true, adds the InstanceId dimension with the value of the EC2 instance id (default false)
  • omitGCPauseMetrics: Boolean - If true, omits the gc_pause metrics (default false)

Important

CloudWatch treats each unique combination of dimensions as a separate metric. For information on how this affects pricing, see the Amazon CloudWatch product information page.