Node.js Language Metrics (Private Beta)
Last updated 03 May 2018
To provide more visibility into the Node.js runtime, the Node.js language metrics feature surfaces additional language-specific time series metrics within Application Metrics. Node.js metrics include Aggregate Time Spent in Garbage Collection, Aggregate Garbage Collections, Event Loop Latency, and Event Loop Usage.
This feature is currently in private beta. If you would like to be flagged in, or have questions or feedback, you can reach us at email@example.com.
Node.js language metrics are available for all paid dynos (Hobby and above) and Private Spaces.
For general information on metrics display settings, please refer to the language runtime metrics parent document.
First, enable the Language Metrics flag on your application. You can do this via the Dashboard or the CLI. To enable it through Dashboard, open the metrics preferences panel and turn on the Enhanced Language Metrics toggle:
Alternatively, to enable it through the Heroku CLI:
$ heroku labs:enable "runtime-heroku-metrics" -a "my-app-name"
Next, if you haven’t already, please contact us with the names of your apps to be flagged into the private beta.
You can continue with the rest of the steps, but will not see any Node.js metrics in your application’s dashboard until your applications are flagged into the private beta and restarted.
Verify your version of Node.js
In order to use Node.js Metrics you must be running Node v8.0.0 or higher, the current LTS release. You can find the version you are using on your local machine by running:
$ node --version v8.11.1
Add the Node.js Metrics buildpack
The next step is to add the Node.js Metrics buildpack to your application. This buildpack is used to setup the process that allows your application to export Node.js specific metrics to Heroku. Adding the buildpack can be accomplished through either the CLI or the dashboard.
Adding the buildpack via the CLI
To add the buildpack using the command line interface (CLI), run the following:
$ heroku buildpacks:add https://github.com/heroku/heroku-nodejs-metrics-buildpack -a "my-app-name"
Adding the buildpack via the Dashboard
From the Settings tab for your app add the buildpack like so:
The Node.js Metrics buildpack must be listed after the Node.js buildpack because it is dependent on npm. If they are out of order, you can go to the app settings tab on the dashboard interface to reorder them.
To finish set up, you must redeploy your application. You can do this by creating an empty commit and pushing to Heroku like so:
$ git commit --allow-empty -m "Enable Node.js Language Metrics" $ git push heroku master
After a few minutes, you will begin receiving metrics which can be viewed via the application metrics tab.
It may take a few minutes for these metrics to become available after the steps above are completed.
Aggregate Time Spent in Garbage Collection
This plot tracks the total pause time (when app execution is halted) to run garbage collection for each rollup across all dynos of the current process type. It also displays the percentage of the time during the rollup that was spent running the garbage collector.
Aggregate Garbage Collections
The number of GC collection, aggregated across all dynos, is displayed on this plot.
Event Loop Latency
At the heart of Node’s asynchronous model is the Event Loop. Your Node.js app is single-threaded and can only process one request at a time, but when it makes an asynchronous request, like a database query, it yields the thread back to the event loop. Event Loop Latency refers to the amount of time you code runs before yielding back to the event loop. High event loop latency can make it difficult to scale your application as traffic grows.
The latency of the event loop, aggregated across all dynos, and displayed as a median, 95th percentile, 99th percentile, and maximum latency, is displayed on this plot.
Event Loop Usage
The percentage of time that the event loop is being blocked by work. A high percentage could indicate that your app is under a high load and may be under-provisioned.
The Event Loop Usage plot displays the minimum, maximum, and average of the observations taken during each rollup across all dynos of the current process type regarding the percentage usage of the event loop.
Disabling Metrics Collection
To disable Node.js metrics collection, simply toggle off the Enhanced Language Metrics toggle via the Metrics Preferences panel, or using this CLI command:
$ heroku labs:disable "runtime-heroku-metrics" -a "my-app-name"